Skip to content

Commit

Permalink
Added client and relay support for requesting the AFTR name, necessar…
Browse files Browse the repository at this point in the history
…y for discovering the DS-Lite carrier grade NAT server, from DHCPv6 servers in DS-Lite using cable provider networks
  • Loading branch information
noctarius committed Apr 2, 2018
1 parent 24ee2a4 commit 11a1064
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 2 deletions.
10 changes: 9 additions & 1 deletion cfparse.y
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static void cleanup_cflist __P((struct cf_list *));
%token ADDRESS
%token REQUEST SEND ALLOW PREFERENCE
%token HOST HOSTNAME DUID
%token OPTION RAPID_COMMIT DNS_SERVERS DNS_NAME NTP_SERVERS REFRESHTIME
%token OPTION RAPID_COMMIT DNS_SERVERS DNS_NAME NTP_SERVERS REFRESHTIME AFTR_NAME
%token SIP_SERVERS SIP_NAME
%token NIS_SERVERS NIS_NAME
%token NISP_SERVERS NISP_NAME
Expand Down Expand Up @@ -744,6 +744,14 @@ dhcpoption:
/* currently no value */
$$ = l;
}
| AFTR_NAME
{
struct cf_list *l;

MAKE_CFLIST(l, DHCPOPT_AFTR_NAME, NULL, NULL);
/* no value */
$$ = l;
}
;

rangeparam:
Expand Down
1 change: 1 addition & 0 deletions cftoken.l
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ ecl \}
<S_CNF>bcmcs-server-address { DECHO; return (BCMCS_SERVERS); }
<S_CNF>bcmcs-server-domain-name { DECHO; return (BCMCS_NAME); }
<S_CNF>refreshtime { DECHO; return (REFRESHTIME); }
<S_CNF>aftr-name { DECHO; return (AFTR_NAME); }
/* provided for a backward compatibility to WIDE-DHCPv6 before Oct 1 2006 */
<S_CNF>nis-server-domain-name { DECHO; return (NIS_NAME); }
Expand Down
24 changes: 24 additions & 0 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,9 @@ dhcp6_clear_options(optinfo)
if (optinfo->ifidopt_id != NULL)
free(optinfo->ifidopt_id);

if (optinfo->aftr_name_val != NULL)
free(optinfo->aftr_name_val);

dhcp6_init_options(optinfo);
}

Expand Down Expand Up @@ -1444,6 +1447,12 @@ dhcp6_copy_options(dst, src)
memcpy(dst->ifidopt_id, src->ifidopt_id, src->ifidopt_len);
}

if (src->aftr_name_val != NULL)
if ((dst->aftr_name_val = malloc(src->aftr_name_val)) == NULL)
goto fail;
dst->aftr_name_len = src->aftr_name_len;
memcpy(dst->aftr_name_val, src->aftr_name_val, src->aftr_name_len);

dst->authflags = src->authflags;
dst->authproto = src->authproto;
dst->authalgorithm = src->authalgorithm;
Expand Down Expand Up @@ -1872,6 +1881,12 @@ dhcp6_get_options(p, ep, optinfo)
dhcp6_clear_list(&sublist);

break;
case DH6OPT_AFTR_NAME:
if ((optinfo->aftr_name_val = malloc(optlen)) == NULL)
goto fail;
memcpy(optinfo->aftr_name_val, cp, optlen);
optinfo->aftr_name_len = optlen;
break;
default:
/* no option specific behavior */
dprintf(LOG_INFO, FNAME,
Expand Down Expand Up @@ -2462,6 +2477,13 @@ dhcp6_set_options(type, optbp, optep, optinfo)
}
}

if (optinfo->aftr_name_val) {
if (copy_option(DH6OPT_AFTR_NAME, optinfo->aftr_name_len,
optinfo->aftr_name_val, &p, optep, &len) != 0) {
goto fail;
}
}

if (optinfo->refreshtime != DH6OPT_REFRESHTIME_UNDEF) {
u_int32_t p32 = (u_int32_t)optinfo->refreshtime;

Expand Down Expand Up @@ -3052,6 +3074,8 @@ dhcp6optstr(type)
return ("subscriber ID");
case DH6OPT_CLIENT_FQDN:
return ("client FQDN");
case DH6OPT_AFTR_NAME:
return ("AFTR name");
default:
snprintf(genstr, sizeof(genstr), "opt_%d", type);
return (genstr);
Expand Down
3 changes: 3 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,7 @@ add_options(opcode, ifc, cfl0)
case DHCPOPT_BCMCS:
case DHCPOPT_BCMCSNAME:
case DHCPOPT_REFRESHTIME:
case DHCPOPT_AFTR_NAME:
switch (cfl->type) {
case DHCPOPT_SIP:
opttype = DH6OPT_SIP_SERVER_A;
Expand Down Expand Up @@ -1687,6 +1688,8 @@ add_options(opcode, ifc, cfl0)
case DHCPOPT_REFRESHTIME:
opttype = DH6OPT_REFRESHTIME;
break;
case DHCPOPT_AFTR_NAME:
opttype = DH6OPT_AFTR_NAME;
}
switch(opcode) {
case DHCPOPTCODE_REQUEST:
Expand Down
3 changes: 2 additions & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ enum { DECL_SEND, DECL_ALLOW, DECL_INFO_ONLY, DECL_REQUEST, DECL_DUID,
DHCPOPT_REFRESHTIME,
DHCPOPT_NIS, DHCPOPT_NISNAME,
DHCPOPT_NISP, DHCPOPT_NISPNAME,
DHCPOPT_BCMCS, DHCPOPT_BCMCSNAME,
DHCPOPT_BCMCS, DHCPOPT_BCMCSNAME,
DHCPOPT_AFTR_NAME,
CFLISTENT_GENERIC,
IACONF_PIF, IACONF_PREFIX, IACONF_ADDR,
DHCPOPT_SIP, DHCPOPT_SIPNAME,
Expand Down
5 changes: 5 additions & 0 deletions dhcp6.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ struct dhcp6_optinfo {
#define ifidopt_len ifidopt.dv_len
#define ifidopt_id ifidopt.dv_buf

struct dhcp6_vbuf aftr_name; /* AFTR DNS name */
#define aftr_name_len aftr_name.dv_len
#define aftr_name_val aftr_name.dv_buf

u_int authflags;
#define DHCP6OPT_AUTHFLAG_NOINFO 0x1
int authproto;
Expand Down Expand Up @@ -309,6 +313,7 @@ struct dhcp6_relay {
#define DH6OPT_REMOTE_ID 37
#define DH6OPT_SUBSCRIBER_ID 38
#define DH6OPT_CLIENT_FQDN 39
#define DH6OPT_AFTR_NAME 64

/* The followings are KAME specific. */

Expand Down
15 changes: 15 additions & 0 deletions dhcp6c_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ static char nispserver_str[] = "new_nisp_servers";
static char nispname_str[] = "new_nisp_name";
static char bcmcsserver_str[] = "new_bcmcs_servers";
static char bcmcsname_str[] = "new_bcmcs_name";
static char aftr_name_str[] = "new_aftr_name";

int
client6_script(scriptpath, state, optinfo)
Expand Down Expand Up @@ -153,6 +154,8 @@ client6_script(scriptpath, state, optinfo)
bcmcsnamelen += v->val_vbuf.dv_len;
}
envc += bcmcsnamelen ? 1 : 0;
if (&optinfo->aftr_name_val != NULL && &optinfo->aftr_name_len > 0)
envc++;

/* allocate an environments array */
if ((envp = malloc(sizeof (char *) * envc)) == NULL) {
Expand Down Expand Up @@ -379,6 +382,18 @@ client6_script(scriptpath, state, optinfo)
strlcat(s, " ", elen);
}
}
if (&optinfo->aftr_name_val != NULL && &optinfo->aftr_name_len > 0) {
elen = sizeof(aftr_name_str) + &optinfo->aftr_name.dv_len + 1;
if ((s = envp[i++] = malloc(elen)) == NULL) {
dprintf(LOG_NOTICE, FNAME,
"failed to allocate string for AFTR name");
ret = -1;
goto clean;
}
memset(s, 0, elen);
snprintf(s, elen, "%s=", aftr_name_str);
strlcat(s, &optinfo->aftr_name.dv_buf, elen);
}

/* launch the script */
pid = fork();
Expand Down

0 comments on commit 11a1064

Please sign in to comment.