/src/dnsmasq/src/outpacket.c
Line | Count | Source |
1 | | /* dnsmasq is Copyright (c) 2000-2026 Simon Kelley |
2 | | |
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 | | |
22 | | static size_t outpacket_counter; |
23 | | |
24 | | void end_opt6(int container) |
25 | 0 | { |
26 | 0 | uint8_t *p = (uint8_t *)daemon->outpacket.iov_base + container + 2; |
27 | 0 | u16 len = outpacket_counter - container - 4 ; |
28 | | |
29 | 0 | PUTSHORT(len, p); |
30 | 0 | } |
31 | | |
32 | | void reset_counter(void) |
33 | 0 | { |
34 | | /* Clear out buffer when starting from beginning */ |
35 | 0 | if (daemon->outpacket.iov_base) |
36 | 0 | memset(daemon->outpacket.iov_base, 0, daemon->outpacket.iov_len); |
37 | | |
38 | 0 | save_counter(0); |
39 | 0 | } |
40 | | |
41 | | int save_counter(int newval) |
42 | 0 | { |
43 | 0 | int ret = outpacket_counter; |
44 | | |
45 | 0 | if (newval != -1) |
46 | 0 | outpacket_counter = newval; |
47 | |
|
48 | 0 | return ret; |
49 | 0 | } |
50 | | |
51 | | void *expand(size_t headroom) |
52 | 0 | { |
53 | 0 | uint8_t *ret; |
54 | |
|
55 | 0 | if (expand_buf(&daemon->outpacket, outpacket_counter + headroom)) |
56 | 0 | { |
57 | 0 | ret = (uint8_t *)daemon->outpacket.iov_base + outpacket_counter; |
58 | 0 | outpacket_counter += headroom; |
59 | 0 | return ret; |
60 | 0 | } |
61 | | |
62 | 0 | return NULL; |
63 | 0 | } |
64 | | |
65 | | int new_opt6(int opt) |
66 | 0 | { |
67 | 0 | int ret = outpacket_counter; |
68 | 0 | unsigned char *p; |
69 | |
|
70 | 0 | if ((p = expand(4))) |
71 | 0 | { |
72 | 0 | PUTSHORT(opt, p); |
73 | 0 | PUTSHORT(0, p); |
74 | 0 | } |
75 | |
|
76 | 0 | return ret; |
77 | 0 | } |
78 | | |
79 | | void *put_opt6(void *data, size_t len) |
80 | 0 | { |
81 | 0 | void *p; |
82 | |
|
83 | 0 | if ((p = expand(len)) && data) |
84 | 0 | memcpy(p, data, len); |
85 | | |
86 | 0 | return p; |
87 | 0 | } |
88 | | |
89 | | void put_opt6_long(unsigned int val) |
90 | 0 | { |
91 | 0 | unsigned char *p; |
92 | | |
93 | 0 | if ((p = expand(4))) |
94 | 0 | PUTLONG(val, p); |
95 | 0 | } |
96 | | |
97 | | void put_opt6_short(unsigned int val) |
98 | 0 | { |
99 | 0 | uint8_t *p; |
100 | |
|
101 | 0 | if ((p = expand(2))) |
102 | 0 | PUTSHORT(val, p); |
103 | 0 | } |
104 | | |
105 | | void put_opt6_char(unsigned int val) |
106 | 0 | { |
107 | 0 | unsigned char *p; |
108 | |
|
109 | 0 | if ((p = expand(1))) |
110 | 0 | *p = val; |
111 | 0 | } |
112 | | |
113 | | void put_opt6_string(char *s) |
114 | 0 | { |
115 | 0 | put_opt6(s, strlen(s)); |
116 | 0 | } |
117 | | |
118 | | #endif |