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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
|
From: Jeremie Corbier <jeremie+debian@famille-corbier.net>
Date: Tue, 6 Apr 2010 15:51:14 +0200
Subject: Add new feature: dhcp6c profiles
This patch enables users to define interface profiles so one can configure a
group of interfaces the same way without having to provide an interface
statement for each.
Signed-off-by: Jeremie Corbier <jeremie@famille-corbier.net>
---
cfparse.y | 23 +++-
cftoken.l | 10 ++
config.c | 334 +++++++++++++++++++++++++++++++++-------------------------
config.h | 3 +
dhcp6c.8 | 9 ++
dhcp6c.c | 5 +-
dhcp6c.conf.5 | 7 ++
7 files changed, 245 insertions(+), 146 deletions(-)
diff --git a/cfparse.y b/cfparse.y
index dcac3d7..c79d131 100644
--- a/cfparse.y
+++ b/cfparse.y
@@ -83,6 +83,7 @@ extern void yyerror __P((char *, ...))
} while (0)
static struct cf_namelist *iflist_head, *hostlist_head, *iapdlist_head;
+static struct cf_namelist *profilelist_head;
static struct cf_namelist *addrpoollist_head;
static struct cf_namelist *authinfolist_head, *keylist_head;
static struct cf_namelist *ianalist_head;
@@ -102,6 +103,7 @@ static void cleanup_cflist __P((struct cf_list *));
%}
%token INTERFACE IFNAME
+%token PROFILE PROFILENAME
%token PREFIX_INTERFACE SLA_ID SLA_LEN DUID_ID
%token ID_ASSOC IA_PD IAID IA_NA
%token ADDRESS
@@ -133,7 +135,7 @@ static void cleanup_cflist __P((struct cf_list *));
}
%type <str> IFNAME HOSTNAME AUTHNAME KEYNAME DUID_ID STRING QSTRING IAID
-%type <str> POOLNAME
+%type <str> POOLNAME PROFILENAME
%type <num> NUMBER duration authproto authalg authrdm
%type <list> declaration declarations dhcpoption ifparam ifparams
%type <list> address_list address_list_ent dhcpoption_list
@@ -153,6 +155,7 @@ statements:
statement:
interface_statement
+ | profile_statement
| host_statement
| option_statement
| ia_statement
@@ -174,6 +177,18 @@ interface_statement:
}
;
+profile_statement:
+ PROFILE PROFILENAME BCL declarations ECL EOS
+ {
+ struct cf_namelist *profilelist;
+
+ MAKE_NAMELIST(profilelist, $2, $4);
+
+ if (add_namelist(profilelist, &profilelist_head))
+ return (-1);
+ }
+ ;
+
host_statement:
HOST HOSTNAME BCL declarations ECL EOS
{
@@ -1224,6 +1239,8 @@ cleanup()
{
cleanup_namelist(iflist_head);
iflist_head = NULL;
+ cleanup_namelist(profilelist_head);
+ profilelist_head = NULL;
cleanup_namelist(hostlist_head);
hostlist_head = NULL;
cleanup_namelist(iapdlist_head);
@@ -1318,6 +1335,9 @@ cf_post_config()
if (configure_pool(addrpoollist_head))
config_fail();
+ if (configure_profile(profilelist_head))
+ config_fail();
+
if (configure_interface(iflist_head))
config_fail();
@@ -1337,4 +1357,5 @@ void
cf_init()
{
iflist_head = NULL;
+ profilelist_head = NULL;
}
diff --git a/cftoken.l b/cftoken.l
index ad4128d..4c9ed10 100644
--- a/cftoken.l
+++ b/cftoken.l
@@ -111,6 +111,7 @@ ecl \}
%s S_CNF
%s S_IFACE
+%s S_PROFILE
%s S_PREF
%s S_HOST
%s S_DUID
@@ -137,6 +138,15 @@ ecl \}
return (IFNAME);
}
+ /* profile configuration */
+<S_CNF>profile { DECHO; BEGIN S_PROFILE; return (PROFILE); }
+<S_PROFILE>{string} {
+ DECHO;
+ yylval.str = strdup(yytext);
+ BEGIN S_CNF;
+ return (PROFILENAME);
+}
+
/* host configuration */
<S_CNF>host { DECHO; BEGIN S_HOST; return (HOST); }
<S_HOST>{string} {
diff --git a/config.c b/config.c
index 3721545..23598fc 100644
--- a/config.c
+++ b/config.c
@@ -61,6 +61,7 @@
#include <lease.h>
extern int errno;
+char *profile = NULL;
struct prefix_ifconf *prefix_ifconflist;
struct dhcp6_list siplist, sipnamelist, dnslist, dnsnamelist, ntplist;
@@ -70,6 +71,7 @@ struct dhcp6_list bcmcslist, bcmcsnamelist;
long long optrefreshtime;
static struct dhcp6_ifconf *dhcp6_ifconflist;
+static struct dhcp6_ifconf *dhcp6_profileconflist;
struct ia_conflist ia_conflist0;
static struct host_conf *host_conflist0, *host_conflist;
static struct keyinfo *key_list, *key_list0;
@@ -134,6 +136,8 @@ 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_interface_or_profile __P((struct cf_namelist *,
+ struct dhcp6_ifconf **));
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 *));
@@ -149,170 +153,199 @@ configure_interface(iflist)
struct cf_namelist *iflist;
{
struct cf_namelist *ifp;
- struct dhcp6_ifconf *ifc;
- char *cp;
for (ifp = iflist; ifp; ifp = ifp->next) {
- struct cf_list *cfl;
-
if (if_nametoindex(ifp->name) == 0) {
debug_printf(LOG_ERR, FNAME, "invalid interface(%s): %s",
ifp->name, strerror(errno));
goto bad;
}
- if ((ifc = malloc(sizeof(*ifc))) == NULL) {
- debug_printf(LOG_ERR, FNAME,
- "memory allocation for %s failed", ifp->name);
+ if (configure_interface_or_profile(ifp, &dhcp6_ifconflist))
goto bad;
- }
- memset(ifc, 0, sizeof(*ifc));
- ifc->next = dhcp6_ifconflist;
- dhcp6_ifconflist = ifc;
+ }
+
+ return (0);
+bad:
+ clear_ifconf(dhcp6_ifconflist);
+ dhcp6_ifconflist = NULL;
+ return (-1);
+}
+
+int
+configure_profile(profilelist)
+ struct cf_namelist *profilelist;
+{
+ struct cf_namelist *profp;
- if ((ifc->ifname = strdup(ifp->name)) == NULL) {
- debug_printf(LOG_ERR, FNAME, "failed to copy ifname");
+ for (profp = profilelist; profp; profp = profp->next) {
+ if (configure_interface_or_profile(profp,
+ &dhcp6_profileconflist))
goto bad;
- }
+ }
- ifc->server_pref = DH6OPT_PREF_UNDEF;
- TAILQ_INIT(&ifc->reqopt_list);
- TAILQ_INIT(&ifc->iaconf_list);
+ return (0);
+bad:
+ clear_ifconf(dhcp6_profileconflist);
+ dhcp6_profileconflist = NULL;
+ return (-1);
+}
- for (cfl = ifp->params; cfl; cfl = cfl->next) {
- switch(cfl->type) {
- case DECL_REQUEST:
- if (dhcp6_mode != DHCP6_MODE_CLIENT) {
- debug_printf(LOG_INFO, FNAME, "%s:%d "
- "client-only configuration",
- configfilename,
- cfl->line);
- goto bad;
- }
- if (add_options(DHCPOPTCODE_REQUEST,
- ifc, cfl->list)) {
- goto bad;
- }
- break;
- case DECL_SEND:
- if (add_options(DHCPOPTCODE_SEND,
- ifc, cfl->list)) {
- goto bad;
- }
- break;
- case DECL_ALLOW:
- if (add_options(DHCPOPTCODE_ALLOW,
- ifc, cfl->list)) {
- goto bad;
- }
- break;
- case DECL_INFO_ONLY:
- if (dhcp6_mode != DHCP6_MODE_CLIENT) {
- debug_printf(LOG_INFO, FNAME, "%s:%d "
- "client-only configuration",
- configfilename, cfl->line);
- goto bad;
- }
- ifc->send_flags |= DHCIFF_INFO_ONLY;
- break;
- case DECL_PREFERENCE:
- if (dhcp6_mode != DHCP6_MODE_SERVER) {
- debug_printf(LOG_INFO, FNAME, "%s:%d "
- "server-only configuration",
- configfilename, cfl->line);
- goto bad;
- }
- ifc->server_pref = (int)cfl->num;
- if (ifc->server_pref < 0 ||
- ifc->server_pref > 255) {
- debug_printf(LOG_INFO, FNAME, "%s:%d "
- "bad value: %d",
+static int configure_interface_or_profile(ifp, conflist)
+ struct cf_namelist *ifp;
+ struct dhcp6_ifconf **conflist;
+{
+ struct dhcp6_ifconf *conf;
+ char *cp;
+ struct cf_list *cfl;
+
+ if ((conf = malloc(sizeof(*conf))) == NULL) {
+ debug_printf(LOG_ERR, FNAME,
+ "memory allocation for %s failed", ifp->name);
+ return (-1);
+ }
+ memset(conf, 0, sizeof(*conf));
+ conf->next = *conflist;
+ *conflist = conf;
+
+ if ((conf->ifname = strdup(ifp->name)) == NULL) {
+ debug_printf(LOG_ERR, FNAME, "failed to copy interface or "
+ "profile name");
+ return (-1);
+ }
+
+ conf->server_pref = DH6OPT_PREF_UNDEF;
+ TAILQ_INIT(&conf->reqopt_list);
+ TAILQ_INIT(&conf->iaconf_list);
+
+ for (cfl = ifp->params; cfl; cfl = cfl->next) {
+ switch(cfl->type) {
+ case DECL_REQUEST:
+ if (dhcp6_mode != DHCP6_MODE_CLIENT) {
+ debug_printf(LOG_INFO, FNAME, "%s:%d "
+ "client-only configuration",
+ configfilename,
+ cfl->line);
+ return (-1);
+ }
+ if (add_options(DHCPOPTCODE_REQUEST,
+ conf, cfl->list)) {
+ return (-1);
+ }
+ break;
+ case DECL_SEND:
+ if (add_options(DHCPOPTCODE_SEND,
+ conf, cfl->list)) {
+ return (-1);
+ }
+ break;
+ case DECL_ALLOW:
+ if (add_options(DHCPOPTCODE_ALLOW,
+ conf, cfl->list)) {
+ return (-1);
+ }
+ break;
+ case DECL_INFO_ONLY:
+ if (dhcp6_mode != DHCP6_MODE_CLIENT) {
+ debug_printf(LOG_INFO, FNAME, "%s:%d "
+ "client-only configuration",
+ configfilename, cfl->line);
+ return (-1);
+ }
+ conf->send_flags |= DHCIFF_INFO_ONLY;
+ break;
+ case DECL_PREFERENCE:
+ if (dhcp6_mode != DHCP6_MODE_SERVER) {
+ debug_printf(LOG_INFO, FNAME, "%s:%d "
+ "server-only configuration",
+ configfilename, cfl->line);
+ return (-1);
+ }
+ conf->server_pref = (int)cfl->num;
+ if (conf->server_pref < 0 ||
+ conf->server_pref > 255) {
+ debug_printf(LOG_INFO, FNAME, "%s:%d "
+ "bad value: %d",
+ configfilename, cfl->line,
+ conf->server_pref);
+ return (-1);
+ }
+ break;
+ case DECL_SCRIPT:
+ if (dhcp6_mode != DHCP6_MODE_CLIENT) {
+ debug_printf(LOG_INFO, FNAME, "%s:%d "
+ "client-only configuration",
+ configfilename, cfl->line);
+ return (-1);
+ }
+ if (conf->scriptpath) {
+ debug_printf(LOG_INFO, FNAME,
+ "%s:%d duplicated configuration",
+ configfilename, cfl->line);
+ return (-1);
+ }
+ cp = cfl->ptr;
+ conf->scriptpath = strdup(cp + 1);
+ if (conf->scriptpath == NULL) {
+ debug_printf(LOG_NOTICE, FNAME,
+ "failed to copy script path");
+ return (-1);
+ }
+ cp = conf->scriptpath;
+ if (*cp != '/') {
+ debug_printf(LOG_INFO, FNAME,
+ "script must be an absolute path");
+ return (-1);
+ }
+ cp += strlen(conf->scriptpath) - 1;
+ *cp = '\0'; /* clear the terminating quote */
+ break;
+ case DECL_ADDRESSPOOL:
+ {
+ struct dhcp6_poolspec* spec;
+ struct pool_conf* pool;
+
+ spec = (struct dhcp6_poolspec *)cfl->ptr;
+
+ for (pool = pool_conflist0; pool; pool = pool->next)
+ if (strcmp(spec->name, pool->name) == 0)
+ break;
+ if (pool == NULL) {
+ debug_printf(LOG_ERR, FNAME, "%s:%d "
+ "pool '%s' not found",
configfilename, cfl->line,
- ifc->server_pref);
- goto bad;
- }
- break;
- case DECL_SCRIPT:
- if (dhcp6_mode != DHCP6_MODE_CLIENT) {
- debug_printf(LOG_INFO, FNAME, "%s:%d "
- "client-only configuration",
- configfilename, cfl->line);
- goto bad;
- }
- if (ifc->scriptpath) {
- debug_printf(LOG_INFO, FNAME,
- "%s:%d duplicated configuration",
- configfilename, cfl->line);
- goto bad;
- }
- cp = cfl->ptr;
- ifc->scriptpath = strdup(cp + 1);
- if (ifc->scriptpath == NULL) {
- debug_printf(LOG_NOTICE, FNAME,
- "failed to copy script path");
- goto bad;
+ spec->name);
+ return (-1);
}
- cp = ifc->scriptpath;
- if (*cp != '/') {
- debug_printf(LOG_INFO, FNAME,
- "script must be an absolute path");
- goto bad;
+ if (spec->vltime != DHCP6_DURATION_INFINITE &&
+ (spec->pltime == DHCP6_DURATION_INFINITE ||
+ spec->pltime > spec->vltime)) {
+ debug_printf(LOG_ERR, FNAME, "%s:%d ",
+ configfilename, cfl->line,
+ "specified a larger preferred lifetime "
+ "than valid lifetime");
+ return (-1);
}
- cp += strlen(ifc->scriptpath) - 1;
- *cp = '\0'; /* clear the terminating quote */
- break;
- case DECL_ADDRESSPOOL:
- {
- struct dhcp6_poolspec* spec;
- struct pool_conf* pool;
-
- spec = (struct dhcp6_poolspec *)cfl->ptr;
-
- for (pool = pool_conflist0; pool; pool = pool->next)
- if (strcmp(spec->name, pool->name) == 0)
- break;
- if (pool == NULL) {
- debug_printf(LOG_ERR, FNAME, "%s:%d "
- "pool '%s' not found",
- configfilename, cfl->line,
- spec->name);
- goto bad;
- }
- if (spec->vltime != DHCP6_DURATION_INFINITE &&
- (spec->pltime == DHCP6_DURATION_INFINITE ||
- spec->pltime > spec->vltime)) {
- debug_printf(LOG_ERR, FNAME, "%s:%d ",
- configfilename, cfl->line,
- "specified a larger preferred lifetime "
- "than valid lifetime");
- goto bad;
- }
- ifc->pool = *spec;
- if ((ifc->pool.name = strdup(spec->name)) == NULL) {
- debug_printf(LOG_ERR, FNAME,
- "memory allocation failed");
- goto bad;
- }
- debug_printf(LOG_DEBUG, FNAME,
- "pool '%s' is specified to the interface '%s'",
- ifc->pool.name, ifc->ifname);
+ conf->pool = *spec;
+ if ((conf->pool.name = strdup(spec->name)) == NULL) {
+ debug_printf(LOG_ERR, FNAME,
+ "memory allocation failed");
+ return (-1);
}
- break;
- default:
- debug_printf(LOG_ERR, FNAME, "%s:%d "
- "invalid interface configuration",
- configfilename, cfl->line);
- goto bad;
+ debug_printf(LOG_DEBUG, FNAME,
+ "pool '%s' is specified to the interface '%s'",
+ conf->pool.name, conf->ifname);
}
+ break;
+ default:
+ debug_printf(LOG_ERR, FNAME, "%s:%d "
+ "invalid interface configuration",
+ configfilename, cfl->line);
+ return (-1);
}
}
return (0);
-
- bad:
- clear_ifconf(dhcp6_ifconflist);
- dhcp6_ifconflist = NULL;
- return (-1);
}
int
@@ -1275,6 +1308,8 @@ configure_cleanup()
clear_iaconf(&ia_conflist0);
clear_ifconf(dhcp6_ifconflist);
dhcp6_ifconflist = NULL;
+ clear_ifconf(dhcp6_profileconflist);
+ dhcp6_profileconflist = NULL;
clear_hostconf(host_conflist0);
host_conflist0 = NULL;
clear_keys(key_list0);
@@ -1322,8 +1357,17 @@ configure_commit()
if (strcmp(ifp->ifname, ifc->ifname) == 0)
break;
}
- if (ifc == NULL)
- continue;
+ if (ifc == NULL) {
+ if (profile == NULL)
+ continue;
+ for (ifc = dhcp6_profileconflist; ifc;
+ ifc = ifc->next) {
+ if (strcmp(profile, ifc->ifname) == 0)
+ break;
+ }
+ if (ifc == NULL)
+ continue;
+ }
/* copy new configuration */
ifp->send_flags = ifc->send_flags;
@@ -1349,6 +1393,8 @@ configure_commit()
clear_ifconf(dhcp6_ifconflist);
dhcp6_ifconflist = NULL;
+ clear_ifconf(dhcp6_profileconflist);
+ dhcp6_profileconflist = NULL;
/* clear unused IA configuration */
if (!TAILQ_EMPTY(&ia_conflist0)) {
diff --git a/config.h b/config.h
index bf6dae6..ea8d17c 100644
--- a/config.h
+++ b/config.h
@@ -285,6 +285,8 @@ dhcp6_mode_t;
extern const dhcp6_mode_t dhcp6_mode;
+extern char *profile;
+
extern struct dhcp6_if *dhcp6_if;
extern struct dhcp6_ifconf *dhcp6_iflist;
extern struct prefix_ifconf *prefix_ifconflist;
@@ -304,6 +306,7 @@ extern long long optrefreshtime;
extern struct dhcp6_if *ifinit __P((char *));
extern int ifreset __P((struct dhcp6_if *));
extern int configure_interface __P((struct cf_namelist *));
+extern int configure_profile __P((struct cf_namelist *));
extern int configure_host __P((struct cf_namelist *));
extern int configure_keys __P((struct cf_namelist *));
extern int configure_authinfo __P((struct cf_namelist *));
diff --git a/dhcp6c.8 b/dhcp6c.8
index 1d69c9d..acc8f46 100644
--- a/dhcp6c.8
+++ b/dhcp6c.8
@@ -39,6 +39,7 @@
.Op Fl c Ar configfile
.Op Fl Ddfi
.Op Fl p Ar pid-file
+.Op Fl P Ar profile
.Ar interface
.Op Ar interfaces...
.\"
@@ -92,6 +93,14 @@ Use
.Ar pid-file
to dump the process ID of
.Nm .
+.It Fl P Ar profile
+Use the given
+.Ar profile
+defined in the
+.Nm
+configuration file for
+.Ar interfaces
+which do not have a specific configuration.
.El
.Pp
The program will daemonize itself on invocation unless the
diff --git a/dhcp6c.c b/dhcp6c.c
index 1e897d2..1953f76 100644
--- a/dhcp6c.c
+++ b/dhcp6c.c
@@ -170,7 +170,7 @@ main(argc, argv)
else
progname++;
- while ((ch = getopt(argc, argv, "c:dDfik:p:")) != -1) {
+ while ((ch = getopt(argc, argv, "c:dDfik:p:P:")) != -1) {
switch (ch) {
case 'c':
conffile = optarg;
@@ -193,6 +193,9 @@ main(argc, argv)
case 'p':
pid_file = optarg;
break;
+ case 'P':
+ profile = optarg;
+ break;
default:
usage();
exit(0);
diff --git a/dhcp6c.conf.5 b/dhcp6c.conf.5
index 5fc03d3..3d5d25a 100644
--- a/dhcp6c.conf.5
+++ b/dhcp6c.conf.5
@@ -288,6 +288,13 @@ file, and be created by the same owner who runs the daemon.
.El
.El
.\"
+.Sh Profile statement
+Some setups may require to configure an interface independently from its name.
+Profiles are available for this particular purpose. They follow the same syntax
+as an interface statement except they can be arbitrarily named. It is then
+possible to choose which profile to use for a given interface on the command
+line.
+.\"
.Sh Identity association statement
Identity association
.Pq IA
|