Skip to content

Commit

Permalink
supported the preference option
Browse files Browse the repository at this point in the history
  • Loading branch information
jinmei committed May 17, 2002
1 parent 89dd4b9 commit 4f3fb8b
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 28 deletions.
15 changes: 13 additions & 2 deletions kame/kame/dhcp6/cfparse.y
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $KAME: cfparse.y,v 1.8 2002/05/08 15:53:17 jinmei Exp $ */
/* $KAME: cfparse.y,v 1.9 2002/05/17 01:37:49 jinmei Exp $ */

/*
* Copyright (C) 2002 WIDE Project.
Expand Down Expand Up @@ -49,6 +49,7 @@ extern int cfdebug;
return(-1); \
} \
memset((l), 0, sizeof(*(l))); \
l->line = lineno; \
l->name = (n); \
l->params = (p); \
} while (0)
Expand All @@ -62,6 +63,7 @@ extern int cfdebug;
return(-1); \
} \
memset((l), 0, sizeof(*(l))); \
l->line = lineno; \
l->type = (t); \
l->ptr = (pp); \
l->list = (pl); \
Expand All @@ -77,7 +79,7 @@ static void cleanup_cflist __P((struct cf_list *));

%token INTERFACE IFNAME
%token PREFIX_INTERFACE SLA_ID DUID_ID
%token REQUEST SEND ALLOW
%token REQUEST SEND ALLOW PREFERENCE
%token HOST HOSTNAME DUID
%token RAPID_COMMIT PREFIX_DELEGATION
%token INFO_ONLY
Expand Down Expand Up @@ -199,6 +201,15 @@ declaration:

MAKE_CFLIST(l, DECL_PREFIX, $2, NULL);

$$ = l;
}
| PREFERENCE NUMBER EOS
{
struct cf_list *l;

MAKE_CFLIST(l, DECL_PREFERENCE, NULL, NULL);
l->num = $2;

$$ = l;
}
;
Expand Down
5 changes: 4 additions & 1 deletion kame/kame/dhcp6/cftoken.l
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $KAME: cftoken.l,v 1.8 2002/05/08 15:53:17 jinmei Exp $ */
/* $KAME: cftoken.l,v 1.9 2002/05/17 01:37:49 jinmei Exp $ */

%{
/*
Expand Down Expand Up @@ -88,6 +88,7 @@ ecl \}

%s S_CNF
%s S_IFACE
%s S_PREF
%s S_HOST
%s S_DUID

Expand Down Expand Up @@ -126,6 +127,8 @@ ecl \}

<S_CNF>prefix { DECHO; return(PREFIX); }

<S_CNF>preference { DECHO; return(PREFERENCE); }

/* request */
<S_CNF>request { DECHO; return(REQUEST); }

Expand Down
18 changes: 16 additions & 2 deletions kame/kame/dhcp6/common.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $KAME: common.c,v 1.51 2002/05/16 05:55:48 jinmei Exp $ */
/* $KAME: common.c,v 1.52 2002/05/17 01:37:49 jinmei Exp $ */
/*
* Copyright (C) 1998 and 1999 WIDE Project.
* All rights reserved.
Expand Down Expand Up @@ -593,6 +593,7 @@ dhcp6_get_options(p, ep, optinfo)
struct dhcp6opt *np, opth;
int i, opt, optlen, reqopts;
char *cp, *val;
u_int8_t val8;
struct dhcp6_optconf *optconf;

for (; p + 1 <= ep; p = np) {
Expand Down Expand Up @@ -676,6 +677,11 @@ dhcp6_get_options(p, ep, optinfo)
nextoption:
}
break;
case DH6OPT_PREFERENCE:
if (optlen != 1)
goto malformed;
optinfo->pref = (int)*(u_char *)cp;
break;
case DH6OPT_RAPID_COMMIT:
if (optlen != 0)
goto malformed;
Expand Down Expand Up @@ -833,7 +839,7 @@ get_delegated_prefixes(p, ep, optinfo)
memcpy((p) + 1, (v), (l)); \
(p) = (struct dhcp6opt *)((char *)((p) + 1) + (l)); \
(len) += sizeof(struct dhcp6opt) + (l); \
dprintf(LOG_DEBUG, "set DHCP option %s", dhcpoptstr((t))); \
dprintf(LOG_DEBUG, "%s" "set %s", FNAME, dhcpoptstr((t))); \
} while (0)

int
Expand All @@ -858,6 +864,12 @@ dhcp6_set_options(bp, ep, optinfo)
if (optinfo->rapidcommit)
COPY_OPTION(DH6OPT_RAPID_COMMIT, 0, NULL, p);

if (optinfo->pref != DH6OPT_PREF_UNDEF) {
u_int8_t p8 = (u_int8_t)optinfo->pref;

COPY_OPTION(DH6OPT_PREFERENCE, sizeof(p8), &p8, p);
}

if (!TAILQ_EMPTY(&optinfo->dnslist)) {
struct in6_addr *in6;
struct dnslist *d;
Expand Down Expand Up @@ -989,6 +1001,8 @@ dhcpoptstr(type)
return "server ID";
case DH6OPT_ORO:
return "option request";
case DH6OPT_PREFERENCE:
return "preference";
case DH6OPT_RAPID_COMMIT:
return "rapid commit";
case DH6OPT_DNS:
Expand Down
66 changes: 53 additions & 13 deletions kame/kame/dhcp6/config.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $KAME: config.c,v 1.12 2002/05/16 05:55:48 jinmei Exp $ */
/* $KAME: config.c,v 1.13 2002/05/17 01:37:49 jinmei Exp $ */

/*
* Copyright (C) 2002 WIDE Project.
Expand Down Expand Up @@ -58,6 +58,8 @@ static struct host_conf *host_conflist0, *host_conflist;

enum { DHCPOPTCODE_SEND, DHCPOPTCODE_REQUEST, DHCPOPTCODE_ALLOW };

extern char *configfilename;

static int add_options __P((int, struct dhcp6_ifconf *, struct cf_list *));
static int add_prefix __P((struct host_conf *, struct delegated_prefix_info *));
static void clear_ifconf __P((struct dhcp6_ifconf *));
Expand Down Expand Up @@ -140,9 +142,18 @@ configure_interface(iflist)
goto bad;
}

ifc->server_pref = DH6OPT_PREF_UNDEF;

for (cfl = ifp->params; cfl; cfl = cfl->next) {
switch(cfl->type) {
case DECL_REQUEST:
if (dhcp6_mode != DHCP6_MODE_CLIENT) {
dprintf(LOG_INFO, "%s" "%s:%d "
"client-only configuration",
FNAME, configfilename,
cfl->line);
goto bad;
}
if (add_options(DHCPOPTCODE_REQUEST,
ifc, cfl->list)) {
goto bad;
Expand All @@ -161,12 +172,37 @@ configure_interface(iflist)
}
break;
case DECL_INFO_ONLY:
if (dhcp6_mode != DHCP6_MODE_CLIENT) {
dprintf(LOG_INFO, "%s" "%s:%d "
"client-only configuration",
FNAME, configfilename,
cfl->line);
goto bad;
}
ifc->send_flags |= DHCIFF_INFO_ONLY;
break;
case DECL_PREFERENCE:
if (dhcp6_mode != DHCP6_MODE_SERVER) {
dprintf(LOG_INFO, "%s" "%s:%d "
"server-only configuration",
FNAME, configfilename,
cfl->line);
goto bad;
}
ifc->server_pref = (int)cfl->num;
if (ifc->server_pref < 0 ||
ifc->server_pref > 255) {
dprintf(LOG_INFO, "%s" "%s:%d "
"bad value: %d", FNAME,
configfilename, cfl->line,
ifc->server_pref);
goto bad;
}
break;
default:
dprintf(LOG_ERR, "%s"
dprintf(LOG_ERR, "%s" "%s:%d "
"invalid interface configuration",
FNAME);
FNAME, configfilename, cfl->line);
goto bad;
}
}
Expand Down Expand Up @@ -226,8 +262,9 @@ configure_prefix_interface(iflist)
pif->sla_id = (u_int32_t)cfl->num;
break;
default:
dprintf(LOG_ERR, "%s" "invalid prefix "
"interface configuration", FNAME);
dprintf(LOG_ERR, "%s" "%s:%d "
"invalid configuration", FNAME,
configfilename, cfl->line);
goto bad;
}
}
Expand Down Expand Up @@ -270,16 +307,18 @@ configure_host(hostlist)
switch(cfl->type) {
case DECL_DUID:
if (hconf->duid.duid_id) {
dprintf(LOG_ERR, "%s"
dprintf(LOG_ERR, "%s" "%s:%d "
"duplicated DUID for %s",
FNAME, host->name);
FNAME, configfilename,
cfl->line, host->name);
goto bad;
}
if ((configure_duid((char *)cfl->ptr,
&hconf->duid)) != 0) {
dprintf(LOG_ERR, "%s"
dprintf(LOG_ERR, "%s" "%s:%d "
"failed to configure "
"DUID for %s", FNAME,
configfilename, cfl->line,
host->name);
goto bad;
}
Expand All @@ -289,17 +328,17 @@ configure_host(hostlist)
break;
case DECL_PREFIX:
if (add_prefix(hconf, cfl->ptr)) {
dprintf(LOG_ERR, "%s"
"failed to configure "
"prefix for %s",
dprintf(LOG_ERR, "%s" "failed "
"to configure prefix for %s",
FNAME, host->name);
goto bad;
}
break;
default:
dprintf(LOG_ERR, "%s"
dprintf(LOG_ERR, "%s" "%s:%d "
"invalid host configuration for %s"
FNAME, host->name);
FNAME, configfilename, cfl->line,
host->name);
goto bad;
}
}
Expand Down Expand Up @@ -457,6 +496,7 @@ configure_commit()
clear_options(ifp->request_options);
ifp->request_options = ifc->request_options;
ifc->send_options = NULL;
ifp->server_pref = ifc->server_pref;
}
}
clear_ifconf(dhcp6_ifconflist);
Expand Down
16 changes: 13 additions & 3 deletions kame/kame/dhcp6/config.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $KAME: config.h,v 1.11 2002/05/16 05:55:48 jinmei Exp $ */
/* $KAME: config.h,v 1.12 2002/05/17 01:37:50 jinmei Exp $ */

/*
* Copyright (C) 2002 WIDE Project.
Expand Down Expand Up @@ -56,10 +56,11 @@ struct dhcp6_if {
/* configuration parameters */
u_long send_flags;
u_long allow_flags;

#define DHCIFF_INFO_ONLY 0x1
#define DHCIFF_RAPID_COMMIT 0x2

int server_pref; /* server preference (server only) */

struct dhcp6_optconf *send_options;
struct dhcp6_optconf *request_options;

Expand Down Expand Up @@ -90,6 +91,8 @@ struct dhcp6_ifconf {
u_long send_flags;
u_long allow_flags;

int server_pref; /* server preference (server only) */

struct dhcp6_optconf *request_options;
struct dhcp6_optconf *send_options;
struct dhcp6_optconf *allow_options;
Expand Down Expand Up @@ -130,12 +133,14 @@ struct dhcp6_optconf {
struct cf_namelist {
struct cf_namelist *next;
char *name;
int line; /* the line number of the config file */
struct cf_list *params;
};

struct cf_list {
struct cf_list *next;
int type;
int line; /* the line number of the config file */

/* type dependent values: */
long long num;
Expand All @@ -144,10 +149,15 @@ struct cf_list {
};

enum {DECL_SEND, DECL_ALLOW, DECL_INFO_ONLY, DECL_REQUEST, DECL_DUID,
DECL_PREFIX,
DECL_PREFIX, DECL_PREFERENCE,
IFPARAM_SLA_ID,
DHCPOPT_RAPID_COMMIT, DHCPOPT_PREFIX_DELEGATION};

typedef enum {DHCP6_MODE_SERVER, DHCP6_MODE_CLIENT, DHCP6_MODE_RELAY }
dhcp6_mode_t;

extern const dhcp6_mode_t dhcp6_mode;

extern struct dhcp6_if *dhcp6_if;
extern struct dhcp6_ifconf *dhcp6_iflist;
extern struct prefix_ifconf *prefix_ifconflist;
Expand Down
9 changes: 6 additions & 3 deletions kame/kame/dhcp6/dhcp6c.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $KAME: dhcp6c.c,v 1.80 2002/05/16 05:55:48 jinmei Exp $ */
/* $KAME: dhcp6c.c,v 1.81 2002/05/17 01:37:50 jinmei Exp $ */
/*
* Copyright (C) 1998 and 1999 WIDE Project.
* All rights reserved.
Expand Down Expand Up @@ -75,6 +75,8 @@
static int debug = 0;
static int signaled = 0;

const dhcp6_mode_t dhcp6_mode = DHCP6_MODE_CLIENT;

char *device = NULL;

int insock; /* inbound udp port */
Expand Down Expand Up @@ -850,8 +852,9 @@ client6_recvadvert(ifp, dh6, len, optinfo)
dprintf(LOG_INFO, "%s" "no server ID option", FNAME);
return -1;
} else {
dprintf(LOG_DEBUG, "%s" "server ID: %s", FNAME,
duidstr(&optinfo->serverID));
dprintf(LOG_DEBUG, "%s" "server ID: %s, pref=%d", FNAME,
duidstr(&optinfo->serverID),
optinfo->pref);
}
if (optinfo->clientID.duid_len == 0) {
dprintf(LOG_INFO, "%s" "no client ID option", FNAME);
Expand Down
Loading

0 comments on commit 4f3fb8b

Please sign in to comment.