blob: d20bd33a64d55a21839d4efa61b6ac2bbfb16e85 [file] [log] [blame]
Simon Kelleyd1ced3a2018-01-01 22:18:03 +00001/* dnsmasq is Copyright (c) 2000-2018 Simon Kelley
Simon Kelleyc5ad4e72012-02-24 16:06:20 +00002
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 dated June, 1991, or
6 (at your option) version 3 dated 29 June, 2007.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
15*/
16
17
18#include "dnsmasq.h"
19
20#ifdef HAVE_DHCP6
21
22static size_t outpacket_counter;
23
24void end_opt6(int container)
25{
26 void *p = daemon->outpacket.iov_base + container + 2;
27 u16 len = outpacket_counter - container - 4 ;
28
29 PUTSHORT(len, p);
30}
31
Simon Kelleyfa785732016-07-22 20:56:01 +010032void reset_counter(void)
33{
Josh Soref730c6742017-02-06 16:14:04 +000034 /* Clear out buffer when starting from beginning */
Simon Kelleyfa785732016-07-22 20:56:01 +010035 if (daemon->outpacket.iov_base)
36 memset(daemon->outpacket.iov_base, 0, daemon->outpacket.iov_len);
37
38 save_counter(0);
39}
40
Simon Kelleyc5ad4e72012-02-24 16:06:20 +000041int save_counter(int newval)
42{
43 int ret = outpacket_counter;
Simon Kelleyfa785732016-07-22 20:56:01 +010044
Simon Kelleyc5ad4e72012-02-24 16:06:20 +000045 if (newval != -1)
46 outpacket_counter = newval;
47
48 return ret;
49}
50
51void *expand(size_t headroom)
52{
53 void *ret;
54
55 if (expand_buf(&daemon->outpacket, outpacket_counter + headroom))
56 {
57 ret = daemon->outpacket.iov_base + outpacket_counter;
58 outpacket_counter += headroom;
59 return ret;
60 }
61
62 return NULL;
63}
64
65int new_opt6(int opt)
66{
67 int ret = outpacket_counter;
68 void *p;
69
70 if ((p = expand(4)))
71 {
72 PUTSHORT(opt, p);
73 PUTSHORT(0, p);
74 }
75
76 return ret;
77}
78
79void *put_opt6(void *data, size_t len)
80{
81 void *p;
82
Simon Kelleyff7eea22013-09-04 18:01:38 +010083 if ((p = expand(len)) && data)
Simon Kelleyc5ad4e72012-02-24 16:06:20 +000084 memcpy(p, data, len);
Simon Kelleyff7eea22013-09-04 18:01:38 +010085
Simon Kelleyc5ad4e72012-02-24 16:06:20 +000086 return p;
87}
88
89void put_opt6_long(unsigned int val)
90{
91 void *p;
92
93 if ((p = expand(4)))
94 PUTLONG(val, p);
95}
96
97void put_opt6_short(unsigned int val)
98{
99 void *p;
100
101 if ((p = expand(2)))
102 PUTSHORT(val, p);
103}
104
105void put_opt6_char(unsigned int val)
106{
107 unsigned char *p;
108
109 if ((p = expand(1)))
110 *p = val;
111}
112
113void put_opt6_string(char *s)
114{
115 put_opt6(s, strlen(s));
116}
117
118#endif