-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch-config.c
399 lines (373 loc) · 11 KB
/
patch-config.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
--- config.c.orig 2017-02-28 19:06:15.000000000 +0000
+++ config.c 2024-04-13 14:12:18.000000000 +0000
@@ -53,12 +53,12 @@
#include <time.h>
#endif
-#include <dhcp6.h>
-#include <config.h>
-#include <common.h>
-#include <auth.h>
-#include <base64.h>
-#include <lease.h>
+#include "dhcp6.h"
+#include "config.h"
+#include "common.h"
+#include "auth.h"
+#include "base64.h"
+#include "lease.h"
extern int errno;
@@ -70,7 +70,7 @@
long long optrefreshtime;
static struct dhcp6_ifconf *dhcp6_ifconflist;
-struct ia_conflist ia_conflist0;
+static struct ia_conflist ia_conflist0;
static struct host_conf *host_conflist0, *host_conflist;
static struct keyinfo *key_list, *key_list0;
static struct authinfo *auth_list, *auth_list0;
@@ -107,6 +107,9 @@
char *scriptpath; /* path to config script (client only) */
+ struct duid duid;
+ struct rawop_list rawops;
+
struct dhcp6_list reqopt_list;
struct ia_conflist iaconf_list;
@@ -123,27 +126,89 @@
extern long long cf_refreshtime;
extern char *configfilename;
-static struct keyinfo *find_keybyname __P((struct keyinfo *, char *));
-static int add_pd_pif __P((struct iapd_conf *, struct cf_list *));
-static int add_options __P((int, struct dhcp6_ifconf *, struct cf_list *));
-static int add_prefix __P((struct dhcp6_list *, char *, int,
- struct dhcp6_prefix *));
-static void clear_pd_pif __P((struct iapd_conf *));
-static void clear_ifconf __P((struct dhcp6_ifconf *));
-static void clear_iaconf __P((struct ia_conflist *));
-static void clear_hostconf __P((struct host_conf *));
-static void clear_keys __P((struct keyinfo *));
-static void clear_authinfo __P((struct authinfo *));
-static int configure_duid __P((char *, struct duid *));
-static int configure_addr __P((struct cf_list *, struct dhcp6_list *, char *));
-static int configure_domain __P((struct cf_list *, struct dhcp6_list *, char *));
-static int get_default_ifid __P((struct prefix_ifconf *));
-static void clear_poolconf __P((struct pool_conf *));
-static struct pool_conf *create_pool __P((char *, struct dhcp6_range *));
-struct host_conf *find_dynamic_hostconf __P((struct duid *));
-static int in6_addr_cmp __P((struct in6_addr *, struct in6_addr *));
-static void in6_addr_inc __P((struct in6_addr *));
+static struct keyinfo *find_keybyname(struct keyinfo *, char *);
+static int add_pd_pif(struct iapd_conf *, struct cf_list *);
+static int add_options(int, struct dhcp6_ifconf *, struct cf_list *);
+static int add_prefix(struct dhcp6_list *, const char *, int,
+ struct dhcp6_prefix *);
+static void clear_pd_pif(struct iapd_conf *);
+static void clear_ifconf(struct dhcp6_ifconf *);
+static void clear_iaconf(struct ia_conflist *);
+static void clear_hostconf(struct host_conf *);
+static void clear_keys(struct keyinfo *);
+static void clear_authinfo(struct authinfo *);
+static int configure_duid(char *, struct duid *);
+static int configure_addr(struct cf_list *, struct dhcp6_list *, const char *);
+static int configure_domain(struct cf_list *, struct dhcp6_list *,
+ const char *);
+static int get_default_ifid(struct prefix_ifconf *);
+static void clear_poolconf(struct pool_conf *);
+static struct pool_conf *create_pool(char *, struct dhcp6_range *);
+struct host_conf *find_dynamic_hostconf(struct duid *);
+static int in6_addr_cmp(struct in6_addr *, struct in6_addr *);
+static void in6_addr_inc(struct in6_addr *);
+/* a debug helper to complete someday if needed... or delete*/
+void list_cfl (char *tag,struct cf_namelist *head)
+{
+ struct cf_namelist *ifp;
+ printf("LIST CFL %s\n",tag);
+
+ for (ifp = head; ifp; ifp = ifp->next) {
+ printf("Do ifp->%s\n", ifp->name);
+ struct cf_list *cfl;
+ for (cfl = ifp->params; cfl; cfl = cfl->next) {
+ printf("Do cfltype->%i lineconf %i ptr=%p sublist=%p\n", cfl->type,cfl->line, cfl->ptr, cfl->list);
+ switch(cfl->type) {
+
+ case DECL_SEND:{
+ struct cf_list *cf0 = (void*)cfl->list;
+ for (; cf0; cf0 = cf0->next) {
+ //printf("SEND opt type %i\n",cf0->type);
+ switch (cf0->type) {
+ case DHCPOPT_RAW:{
+ struct rawoption *op = cf0->ptr;
+ printf("rawop %i datalen %i\n", op->opnum, op->datalen);
+ }
+ break;
+ default:;
+ }
+ }
+ }
+ break;
+ case DECL_SCRIPT:
+ printf("script %s\n", (char *)cfl->ptr);
+ break;
+ default:
+ printf("Unknown option type %i\n", cfl->type);
+ }
+/*
+ case DHCPOPT_RAW:
+ case DHCPOPT_RAPID_COMMIT:
+ case DHCPOPT_AUTHINFO:
+ case DHCPOPT_IA_PD:
+ case DHCPOPT_IA_NA:
+ case DHCPOPT_SIP:
+ case DHCPOPT_SIPNAME:
+ case DHCPOPT_DNS:
+ case DHCPOPT_DNSNAME:
+ case DHCPOPT_NTP:
+ case DHCPOPT_NIS:
+ case DHCPOPT_NISNAME:
+ case DHCPOPT_NISP:
+ case DHCPOPT_NISPNAME:
+ case DHCPOPT_BCMCS:
+ case DHCPOPT_BCMCSNAME:
+ case DHCPOPT_REFRESHTIME:
+ printf("Known option type %i\n", cfl->type);
+ break;
+ default:
+ printf("Unknown option type %i\n", cfl->type);
+*/
+ }
+ }
+}
+
int
configure_interface(iflist)
struct cf_namelist *iflist;
@@ -178,6 +243,7 @@
ifc->server_pref = DH6OPT_PREF_UNDEF;
TAILQ_INIT(&ifc->reqopt_list);
TAILQ_INIT(&ifc->iaconf_list);
+ TAILQ_INIT(&ifc->rawops);
for (cfl = ifp->params; cfl; cfl = cfl->next) {
switch(cfl->type) {
@@ -206,6 +272,20 @@
goto bad;
}
break;
+ case DECL_DUID:
+ if ((configure_duid((char *)cfl->ptr,
+ &ifc->duid)) != 0) {
+ d_printf(LOG_ERR, FNAME, "%s:%d "
+ "failed to configure "
+ "DUID for %s",
+ configfilename, cfl->line,
+ ifc->ifname);
+ goto bad;
+ }
+ d_printf(LOG_DEBUG, FNAME,
+ "configure DUID for %s: %s",
+ ifc->ifname, duidstr(&ifc->duid));
+ break;
case DECL_INFO_ONLY:
if (dhcp6_mode != DHCP6_MODE_CLIENT) {
d_printf(LOG_INFO, FNAME, "%s:%d "
@@ -305,8 +385,14 @@
goto bad;
}
}
+
+ if (ifinit(ifp->name) == NULL) {
+ d_printf(LOG_ERR, FNAME, "failed to initialize %s", ifp->name);
+ /* safe to exit here as still parsing */
+ exit(1);
+ }
}
-
+
return (0);
bad:
@@ -355,7 +441,7 @@
/* common initialization */
iac->type = iatype;
- iac->iaid = (u_int32_t)atoi(iap->name);
+ iac->iaid = (uint32_t)atoi(iap->name);
TAILQ_INIT(&iac->iadata);
TAILQ_INSERT_TAIL(&ia_conflist0, iac, link);
@@ -480,7 +566,7 @@
for (cfl = cfl0->list; cfl; cfl = cfl->next) {
switch(cfl->type) {
case IFPARAM_SLA_ID:
- pif->sla_id = (u_int32_t)cfl->num;
+ pif->sla_id = (uint32_t)cfl->num;
break;
case IFPARAM_SLA_LEN:
pif->sla_len = (int)cfl->num;
@@ -809,7 +895,7 @@
}
lt = localtime(&now);
lt->tm_sec = 0;
-
+
if (strptime(expire, "%Y-%m-%d %H:%M", lt)
== NULL &&
strptime(expire, "%m-%d %H:%M", lt)
@@ -1033,7 +1119,7 @@
configure_addr(cf_addr_list, list0, optname)
struct cf_list *cf_addr_list;
struct dhcp6_list *list0;
- char *optname;
+ const char *optname;
{
struct cf_list *cl;
@@ -1071,7 +1157,7 @@
configure_domain(cf_name_list, list0, optname)
struct cf_list *cf_name_list;
struct dhcp6_list *list0;
- char *optname;
+ const char *optname;
{
struct cf_list *cl;
@@ -1087,7 +1173,7 @@
char *name, *cp;
struct dhcp6_vbuf name_vbuf;
- name = strdup(cl->ptr + 1);
+ name = strdup((char *)cl->ptr + 1);
if (name == NULL) {
d_printf(LOG_ERR, FNAME,
"failed to copy a %s domain name",
@@ -1216,7 +1302,7 @@
if (ifa->ifa_addr->sa_family != AF_LINK)
continue;
- sdl = (struct sockaddr_dl *)ifa->ifa_addr;
+ sdl = (struct sockaddr_dl *)(void *)ifa->ifa_addr;
if (sdl->sdl_alen < 6) {
d_printf(LOG_NOTICE, FNAME,
"link layer address is too short (%s)",
@@ -1309,13 +1395,15 @@
ifp->send_flags = 0;
ifp->allow_flags = 0;
dhcp6_clear_list(&ifp->reqopt_list);
+ rawop_clear_list(&ifp->rawops);
clear_iaconf(&ifp->iaconf_list);
+
ifp->server_pref = DH6OPT_PREF_UNDEF;
if (ifp->scriptpath != NULL)
free(ifp->scriptpath);
ifp->scriptpath = NULL;
ifp->authproto = DHCP6_AUTHPROTO_UNDEF;
- ifp->authalgorithm = DHCP6_AUTHALG_UNDEF;
+ ifp->authalgorithm = DHCP6_AUTHALG_UNDEF;
ifp->authrdm = DHCP6_AUTHRDM_UNDEF;
for (ifc = dhcp6_ifconflist; ifc; ifc = ifc->next) {
@@ -1329,6 +1417,7 @@
ifp->send_flags = ifc->send_flags;
ifp->allow_flags = ifc->allow_flags;
dhcp6_copy_list(&ifp->reqopt_list, &ifc->reqopt_list);
+ rawop_copy_list(&ifp->rawops, &ifc->rawops);
while ((iac = TAILQ_FIRST(&ifc->iaconf_list)) != NULL) {
TAILQ_REMOVE(&ifc->iaconf_list, iac, link);
TAILQ_INSERT_TAIL(&ifp->iaconf_list,
@@ -1345,8 +1434,15 @@
}
ifp->pool = ifc->pool;
ifc->pool.name = NULL;
+
+ if (ifc->duid.duid_id != NULL) {
+ d_printf(LOG_INFO, FNAME, "copying duid");
+ duidcpy(&ifp->duid, &ifc->duid);
+ duidfree(&ifc->duid);
+ }
}
+
clear_ifconf(dhcp6_ifconflist);
dhcp6_ifconflist = NULL;
@@ -1435,6 +1531,7 @@
free(ifc->ifname);
dhcp6_clear_list(&ifc->reqopt_list);
+ rawop_clear_list(&ifc->rawops);
clear_iaconf(&ifc->iaconf_list);
@@ -1592,7 +1689,7 @@
switch (opcode) {
case DHCPOPTCODE_SEND:
iac = find_iaconf(&ia_conflist0, IATYPE_PD,
- (u_int32_t)cfl->num);
+ (uint32_t)cfl->num);
if (iac == NULL) {
d_printf(LOG_ERR, FNAME, "%s:%d "
"IA_PD (%lu) is not defined",
@@ -1617,7 +1714,7 @@
switch (opcode) {
case DHCPOPTCODE_SEND:
iac = find_iaconf(&ia_conflist0, IATYPE_NA,
- (u_int32_t)cfl->num);
+ (uint32_t)cfl->num);
if (iac == NULL) {
d_printf(LOG_ERR, FNAME, "%s:%d "
"IA_NA (%lu) is not defined",
@@ -1638,6 +1735,37 @@
break;
}
break;
+
+ case DHCPOPT_RAW:
+ opttype = DHCPOPT_RAW;
+ struct rawoption *newop, *op;
+ op = (struct rawoption *) cfl->ptr;
+ d_printf(LOG_INFO, FNAME,
+ "add raw option: %d length: %d",
+ op->opnum, op->datalen);
+
+ if ((newop = malloc(sizeof(*newop))) == NULL) {
+ d_printf(LOG_ERR, FNAME,
+ "failed to allocate memory for a new raw option");
+ return(-1);
+ }
+
+ memset(newop, 0, sizeof(*newop));
+
+ newop->opnum = op->opnum;
+ newop->datalen = op->datalen;
+
+ /* copy data */
+ if ((newop->data = malloc(newop->datalen)) == NULL) {
+ d_printf(LOG_ERR, FNAME,
+ "failed to allocate memory for new raw option data");
+ return(-1);
+ }
+ memcpy(newop->data, op->data, newop->datalen);
+
+ TAILQ_INSERT_TAIL(&ifc->rawops, newop, link);
+ break;
+
case DHCPOPT_SIP:
case DHCPOPT_SIPNAME:
case DHCPOPT_DNS:
@@ -1730,7 +1858,7 @@
static int
add_prefix(head, name, type, prefix0)
struct dhcp6_list *head;
- char *name;
+ const char *name;
int type;
struct dhcp6_prefix *prefix0;
{
@@ -1806,7 +1934,7 @@
find_iaconf(head, type, iaid)
struct ia_conflist *head;
int type;
- u_int32_t iaid;
+ uint32_t iaid;
{
struct ia_conf *iac;
@@ -1874,7 +2002,7 @@
find_key(realm, realmlen, id)
char *realm;
size_t realmlen;
- u_int32_t id;
+ uint32_t id;
{
struct keyinfo *key;
@@ -1987,7 +2115,7 @@
{
struct dynamic_hostconf *dynconf = NULL;
struct host_conf *host;
- char* strid = NULL;
+ const char *strid = NULL;
static int init = 1;
if (init) {