349
349
return (memcmp(vb1->dv_buf, vb2->dv_buf, vb1->dv_len));
353
dhcp6_get_addr(optlen, cp, type, list)
356
dhcp6_listval_type_t type;
357
struct dhcp6_list *list;
362
if (optlen % sizeof(struct in6_addr) || optlen == 0) {
363
dprintf(LOG_INFO, FNAME,
364
"malformed DHCP option: type %d, len %d", type, optlen);
367
for (val = cp; val < cp + optlen; val += sizeof(struct in6_addr)) {
368
struct in6_addr valaddr;
370
memcpy(&valaddr, val, sizeof(valaddr));
371
if (dhcp6_find_listval(list,
372
DHCP6_LISTVAL_ADDR6, &valaddr, 0)) {
373
dprintf(LOG_INFO, FNAME, "duplicated %s address (%s)",
374
dhcp6optstr(type), in6addr2str(&valaddr, 0));
378
if (dhcp6_add_listval(list, DHCP6_LISTVAL_ADDR6,
379
&valaddr, NULL) == NULL) {
380
dprintf(LOG_ERR, FNAME,
381
"failed to copy %s address", dhcp6optstr(type));
390
dhcp6_set_addr(type, list, p, optep, len)
391
dhcp6_listval_type_t type;
392
struct dhcp6_list *list;
393
struct dhcp6opt **p, *optep;
396
struct in6_addr *in6;
398
struct dhcp6_listval *d;
401
if (TAILQ_EMPTY(list))
405
optlen = dhcp6_count_list(list) * sizeof(struct in6_addr);
406
if ((tmpbuf = malloc(optlen)) == NULL) {
407
dprintf(LOG_ERR, FNAME,
408
"memory allocation failed for %s options",
412
in6 = (struct in6_addr *)tmpbuf;
413
for (d = TAILQ_FIRST(list); d; d = TAILQ_NEXT(d, link), in6++)
414
memcpy(in6, &d->val_addr6, sizeof(*in6));
415
if (copy_option(type, optlen, tmpbuf, p, optep, len) != 0) {
425
dhcp6_get_domain(optlen, cp, type, list)
428
dhcp6_listval_type_t type;
429
struct dhcp6_list *list;
434
while (val < cp + optlen) {
435
struct dhcp6_vbuf vb;
436
char name[MAXDNAME + 1];
438
if (dnsdecode((u_char **)(void *)&val,
439
(u_char *)(cp + optlen), name, sizeof(name)) == NULL) {
440
dprintf(LOG_INFO, FNAME, "failed to "
441
"decode a %s domain name",
443
dprintf(LOG_INFO, FNAME,
444
"malformed DHCP option: type %d, len %d",
449
vb.dv_len = strlen(name) + 1;
452
if (dhcp6_add_listval(list,
453
DHCP6_LISTVAL_VBUF, &vb, NULL) == NULL) {
454
dprintf(LOG_ERR, FNAME, "failed to "
455
"copy a %s domain name", dhcp6optstr(type));
464
dhcp6_set_domain(type, list, p, optep, len)
465
dhcp6_listval_type_t type;
466
struct dhcp6_list *list;
467
struct dhcp6opt **p, *optep;
471
struct dhcp6_listval *d;
473
char name[MAXDNAME], *cp, *ep;
475
if (TAILQ_EMPTY(list))
478
for (d = TAILQ_FIRST(list); d; d = TAILQ_NEXT(d, link))
479
optlen += (d->val_vbuf.dv_len + 1);
486
if ((tmpbuf = malloc(optlen)) == NULL) {
487
dprintf(LOG_ERR, FNAME, "memory allocation failed for "
488
"%s domain options", dhcp6optstr(type));
493
for (d = TAILQ_FIRST(list); d; d = TAILQ_NEXT(d, link)) {
496
nlen = dnsencode((const char *)d->val_vbuf.dv_buf,
497
name, sizeof (name));
499
dprintf(LOG_ERR, FNAME,
500
"failed to encode a %s domain name",
505
if (ep - cp < nlen) {
506
dprintf(LOG_ERR, FNAME,
507
"buffer length for %s domain name is too short",
512
memcpy(cp, name, nlen);
515
if (copy_option(type, optlen, tmpbuf, p, optep, len) != 0) {
352
524
struct dhcp6_event *
353
525
dhcp6_create_event(ifp, state)
354
526
struct dhcp6_if *ifp;
1364
1560
optinfo->ifidopt_len = optlen;
1366
1562
case DH6OPT_SIP_SERVER_D:
1368
while (val < cp + optlen) {
1369
struct dhcp6_vbuf vb;
1370
char name[MAXDNAME + 1];
1372
if (dnsdecode((u_char **)(void *)&val,
1373
(u_char *)(cp + optlen), name,
1374
sizeof(name)) == NULL) {
1375
dprintf(LOG_INFO, FNAME, "failed to "
1376
"decode a SIP domain name");
1377
goto malformed; /* or proceed? */
1380
vb.dv_len = strlen(name) + 1;
1383
if (dhcp6_add_listval(&optinfo->sipname_list,
1384
DHCP6_LISTVAL_VBUF, &vb, NULL) == NULL) {
1385
dprintf(LOG_ERR, FNAME, "failed to "
1386
"copy a SIP domain name");
1563
if (dhcp6_get_domain(optlen, cp, opt,
1564
&optinfo->sipname_list) == -1)
1567
case DH6OPT_DNSNAME:
1568
if (dhcp6_get_domain(optlen, cp, opt,
1569
&optinfo->dnsname_list) == -1)
1572
case DH6OPT_NIS_DOMAIN_NAME:
1573
if (dhcp6_get_domain(optlen, cp, opt,
1574
&optinfo->nisname_list) == -1)
1577
case DH6OPT_NISP_DOMAIN_NAME:
1578
if (dhcp6_get_domain(optlen, cp, opt,
1579
&optinfo->nispname_list) == -1)
1582
case DH6OPT_BCMCS_SERVER_D:
1583
if (dhcp6_get_domain(optlen, cp, opt,
1584
&optinfo->bcmcsname_list) == -1)
1391
1587
case DH6OPT_SIP_SERVER_A:
1392
if (optlen % sizeof(struct in6_addr) || optlen == 0)
1394
for (val = cp; val < cp + optlen;
1395
val += sizeof(struct in6_addr)) {
1396
memcpy(&valaddr, val, sizeof(valaddr));
1397
if (dhcp6_find_listval(&optinfo->sip_list,
1398
DHCP6_LISTVAL_ADDR6, &valaddr, 0)) {
1399
dprintf(LOG_INFO, FNAME, "duplicated "
1400
"SIP server address (%s)",
1401
in6addr2str(&valaddr, 0));
1405
if (dhcp6_add_listval(&optinfo->sip_list,
1406
DHCP6_LISTVAL_ADDR6, &valaddr, NULL)
1408
dprintf(LOG_ERR, FNAME,
1410
"SIP server address");
1588
if (dhcp6_get_addr(optlen, cp, opt,
1589
&optinfo->sip_list) == -1)
1417
1592
case DH6OPT_DNS:
1418
if (optlen % sizeof(struct in6_addr) || optlen == 0)
1420
for (val = cp; val < cp + optlen;
1421
val += sizeof(struct in6_addr)) {
1422
memcpy(&valaddr, val, sizeof(valaddr));
1423
if (dhcp6_find_listval(&optinfo->dns_list,
1424
DHCP6_LISTVAL_ADDR6, &valaddr, 0)) {
1425
dprintf(LOG_INFO, FNAME, "duplicated "
1427
in6addr2str(&valaddr, 0));
1431
if (dhcp6_add_listval(&optinfo->dns_list,
1432
DHCP6_LISTVAL_ADDR6, &valaddr, NULL)
1434
dprintf(LOG_ERR, FNAME,
1435
"failed to copy DNS address");
1442
case DH6OPT_DNSNAME:
1444
while (val < cp + optlen) {
1445
struct dhcp6_vbuf vb;
1446
char name[MAXDNAME + 1];
1448
if (dnsdecode((u_char **)(void *)&val,
1449
(u_char *)(cp + optlen), name,
1450
sizeof(name)) == NULL) {
1451
dprintf(LOG_INFO, FNAME, "failed to "
1452
"decode a DNS name");
1453
goto malformed; /* or proceed? */
1456
vb.dv_len = strlen(name) + 1;
1459
if (dhcp6_add_listval(&optinfo->dnsname_list,
1460
DHCP6_LISTVAL_VBUF, &vb, NULL) == NULL) {
1461
dprintf(LOG_ERR, FNAME, "failed to "
1467
#ifdef USE_DH6OPT_NTP
1593
if (dhcp6_get_addr(optlen, cp, opt,
1594
&optinfo->dns_list) == -1)
1597
case DH6OPT_NIS_SERVERS:
1598
if (dhcp6_get_addr(optlen, cp, opt,
1599
&optinfo->nis_list) == -1)
1602
case DH6OPT_NISP_SERVERS:
1603
if (dhcp6_get_addr(optlen, cp, opt,
1604
&optinfo->nisp_list) == -1)
1607
case DH6OPT_BCMCS_SERVER_A:
1608
if (dhcp6_get_addr(optlen, cp, opt,
1609
&optinfo->bcmcs_list) == -1)
1468
1612
case DH6OPT_NTP:
1469
if (optlen % sizeof(struct in6_addr) || optlen == 0)
1471
for (val = cp; val < cp + optlen;
1472
val += sizeof(struct in6_addr)) {
1473
memcpy(&valaddr, val, sizeof(valaddr));
1474
if (dhcp6_find_listval(&optinfo->ntp_list,
1475
DHCP6_LISTVAL_ADDR6, &valaddr, 0)) {
1476
dprintf(LOG_INFO, FNAME, "duplicated "
1477
"NTP server address (%s)",
1478
in6addr2str(&valaddr, 0));
1482
if (dhcp6_add_listval(&optinfo->ntp_list,
1483
DHCP6_LISTVAL_ADDR6, &valaddr, NULL)
1485
dprintf(LOG_ERR, FNAME, "failed to "
1486
"copy NTP server address");
1613
if (dhcp6_get_addr(optlen, cp, opt,
1614
&optinfo->ntp_list) == -1)
1494
1617
case DH6OPT_IA_PD:
1495
1618
if (optlen + sizeof(struct dhcp6opt) <
2099
for (d = TAILQ_FIRST(&optinfo->sipname_list); d;
2100
d = TAILQ_NEXT(d, link)) {
2101
optlen += (d->val_vbuf.dv_len + 1);
2104
char name[MAXDNAME], *cp, *ep;
2107
if ((tmpbuf = malloc(optlen)) == NULL) {
2108
dprintf(LOG_ERR, FNAME,
2109
"memory allocation failed for "
2110
"SIP server domain options");
2115
for (d = TAILQ_FIRST(&optinfo->sipname_list); d;
2116
d = TAILQ_NEXT(d, link)) {
2119
nlen = dnsencode((const char *)d->val_vbuf.dv_buf,
2120
name, sizeof (name));
2122
dprintf(LOG_ERR, FNAME,
2123
"failed to encode a SIP server "
2127
if (ep - cp < nlen) {
2128
dprintf(LOG_ERR, FNAME,
2129
"buffer length for SIP server "
2130
"domain name is too short");
2133
memcpy(cp, name, nlen);
2136
if (copy_option(DH6OPT_SIP_SERVER_D, optlen, tmpbuf, &p,
2137
optep, &len) != 0) {
2142
if (!TAILQ_EMPTY(&optinfo->sip_list)) {
2143
struct in6_addr *in6;
2146
optlen = dhcp6_count_list(&optinfo->sip_list) *
2147
sizeof(struct in6_addr);
2148
if ((tmpbuf = malloc(optlen)) == NULL) {
2149
dprintf(LOG_ERR, FNAME,
2150
"memory allocation failed for SIP server options");
2153
in6 = (struct in6_addr *)tmpbuf;
2154
for (d = TAILQ_FIRST(&optinfo->sip_list); d;
2155
d = TAILQ_NEXT(d, link), in6++) {
2156
memcpy(in6, &d->val_addr6, sizeof(*in6));
2158
if (copy_option(DH6OPT_SIP_SERVER_A, optlen, tmpbuf, &p,
2159
optep, &len) != 0) {
2165
if (!TAILQ_EMPTY(&optinfo->dns_list)) {
2166
struct in6_addr *in6;
2169
optlen = dhcp6_count_list(&optinfo->dns_list) *
2170
sizeof(struct in6_addr);
2171
if ((tmpbuf = malloc(optlen)) == NULL) {
2172
dprintf(LOG_ERR, FNAME,
2173
"memory allocation failed for DNS options");
2176
in6 = (struct in6_addr *)tmpbuf;
2177
for (d = TAILQ_FIRST(&optinfo->dns_list); d;
2178
d = TAILQ_NEXT(d, link), in6++) {
2179
memcpy(in6, &d->val_addr6, sizeof(*in6));
2181
if (copy_option(DH6OPT_DNS, optlen, tmpbuf, &p,
2182
optep, &len) != 0) {
2189
for (d = TAILQ_FIRST(&optinfo->dnsname_list); d;
2190
d = TAILQ_NEXT(d, link)) {
2191
optlen += (d->val_vbuf.dv_len + 1);
2194
char name[MAXDNAME], *cp, *ep;
2197
if ((tmpbuf = malloc(optlen)) == NULL) {
2198
dprintf(LOG_ERR, FNAME,
2199
"memory allocation failed for DNS name options");
2204
for (d = TAILQ_FIRST(&optinfo->dnsname_list); d;
2205
d = TAILQ_NEXT(d, link)) {
2208
nlen = dnsencode((const char *)d->val_vbuf.dv_buf,
2209
name, sizeof (name));
2211
dprintf(LOG_ERR, FNAME,
2212
"failed to encode a DNS name");
2215
if (ep - cp < nlen) {
2216
dprintf(LOG_ERR, FNAME,
2217
"buffer length for DNS name is too short");
2220
memcpy(cp, name, nlen);
2223
if (copy_option(DH6OPT_DNSNAME, optlen, tmpbuf, &p,
2224
optep, &len) != 0) {
2230
#ifdef USE_DH6OPT_NTP
2231
if (!TAILQ_EMPTY(&optinfo->ntp_list)) {
2232
struct in6_addr *in6;
2235
optlen = dhcp6_count_list(&optinfo->ntp_list) *
2236
sizeof(struct in6_addr);
2237
if ((tmpbuf = malloc(optlen)) == NULL) {
2238
dprintf(LOG_ERR, FNAME,
2239
"memory allocation failed for NTP options");
2242
in6 = (struct in6_addr *)tmpbuf;
2243
for (d = TAILQ_FIRST(&optinfo->ntp_list); d;
2244
d = TAILQ_NEXT(d, link), in6++) {
2245
memcpy(in6, &d->val_addr6, sizeof(*in6));
2247
if (copy_option(DH6OPT_NTP, optlen, tmpbuf, &p,
2248
optep, &len) != 0) {
2217
if (dhcp6_set_domain(DH6OPT_SIP_SERVER_D, &optinfo->sipname_list,
2218
&p, optep, &len) != 0)
2221
if (dhcp6_set_addr(DH6OPT_SIP_SERVER_A, &optinfo->sip_list,
2222
&p, optep, &len) != 0)
2225
if (dhcp6_set_addr(DH6OPT_DNS, &optinfo->sip_list,
2226
&p, optep, &len) != 0)
2229
if (dhcp6_set_domain(DH6OPT_DNSNAME, &optinfo->dnsname_list,
2230
&p, optep, &len) != 0)
2233
if (dhcp6_set_addr(DH6OPT_NIS_SERVERS, &optinfo->nis_list,
2234
&p, optep, &len) != 0)
2237
if (dhcp6_set_addr(DH6OPT_NISP_SERVERS, &optinfo->nisp_list,
2238
&p, optep, &len) != 0)
2241
if (dhcp6_set_domain(DH6OPT_NIS_DOMAIN_NAME, &optinfo->nisname_list,
2242
&p, optep, &len) != 0)
2245
if (dhcp6_set_domain(DH6OPT_NISP_DOMAIN_NAME, &optinfo->nispname_list,
2246
&p, optep, &len) != 0)
2249
if (dhcp6_set_addr(DH6OPT_NTP, &optinfo->ntp_list,
2250
&p, optep, &len) != 0)
2253
if (dhcp6_set_domain(DH6OPT_BCMCS_SERVER_D, &optinfo->bcmcsname_list,
2254
&p, optep, &len) != 0)
2257
if (dhcp6_set_addr(DH6OPT_BCMCS_SERVER_A, &optinfo->bcmcs_list,
2258
&p, optep, &len) != 0)
2255
2261
for (op = TAILQ_FIRST(&optinfo->iapd_list); op;
2256
2262
op = TAILQ_NEXT(op, link)) {
2851
2855
case DH6OPT_RECONF_MSG:
2852
2856
return ("reconfigure message");
2853
2857
case DH6OPT_SIP_SERVER_D:
2854
return ("SIP server domain name ");
2858
return ("SIP domain name");
2855
2859
case DH6OPT_SIP_SERVER_A:
2856
2860
return ("SIP server address");
2857
2861
case DH6OPT_DNS:
2858
2862
return ("DNS");
2859
2863
case DH6OPT_DNSNAME:
2860
2864
return ("domain search list");
2861
#ifdef USE_DH6OPT_NTP
2862
2865
case DH6OPT_NTP:
2863
2866
return ("NTP server");
2865
2867
case DH6OPT_IA_PD:
2866
2868
return ("IA_PD");
2867
2869
case DH6OPT_IA_PD_PREFIX:
2868
2870
return ("IA_PD prefix");
2869
#ifdef USE_DH6OPT_REFRESHTIME
2870
2871
case DH6OPT_REFRESHTIME:
2871
2872
return ("information refresh time");
2873
case DH6OPT_NIS_SERVERS:
2874
return ("NIS servers");
2875
case DH6OPT_NISP_SERVERS:
2876
return ("NIS+ servers");
2877
case DH6OPT_NIS_DOMAIN_NAME:
2878
return ("NIS domain name");
2879
case DH6OPT_NISP_DOMAIN_NAME:
2880
return ("NIS+ domain name");
2881
case DH6OPT_BCMCS_SERVER_D:
2882
return ("BCMCS domain name");
2883
case DH6OPT_BCMCS_SERVER_A:
2884
return ("BCMCS server address");
2885
case DH6OPT_GEOCONF_CIVIC:
2886
return ("Geoconf Civic");
2887
case DH6OPT_REMOTE_ID:
2888
return ("remote ID");
2889
case DH6OPT_SUBSCRIBER_ID:
2890
return ("subscriber ID");
2891
case DH6OPT_CLIENT_FQDN:
2892
return ("client FQDN");
2874
2894
snprintf(genstr, sizeof(genstr), "opt_%d", type);
2875
2895
return (genstr);