Skip to content

Commit

Permalink
initial implementation of DHCPv6 lifetime option.
Browse files Browse the repository at this point in the history
  • Loading branch information
jinmei committed Mar 21, 2004
1 parent 8295329 commit 2e0e974
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 14 deletions.
3 changes: 2 additions & 1 deletion kame/kame/dhcp6/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# $Id: Makefile.in,v 1.28 2003/11/25 03:52:05 jinmei Exp $
# $Id: Makefile.in,v 1.29 2004/03/21 14:40:51 jinmei Exp $
#

srcdir= @srcdir@
Expand All @@ -25,6 +25,7 @@ CFLAGS+= @DHCPOPT_DNS@ @DH6OPT_DNSNAME@ \
-DCONF_DH6OPT_PREFIX_INFORMATION=@dhcpopt_pinfo@ \
-DCONF_DH6OPT_PREFIX_REQUEST=@dhcpopt_preq@ \
-DCONF_DH6OPT_NTP=@dhcpopt_ntp@ \
-DCONF_DH6OPT_LIFETIME=@dhcpopt_lifetime@

GENSRCS=cfparse.c cftoken.c
CLIENTOBJS= dhcp6c.o common.o config.o prefixconf.o dhcp6c_ia.o timer.o \
Expand Down
32 changes: 29 additions & 3 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.25 2004/01/20 07:24:44 suz Exp $ */
/* $KAME: cfparse.y,v 1.26 2004/03/21 14:40:51 jinmei Exp $ */

/*
* Copyright (C) 2002 WIDE Project.
Expand Down Expand Up @@ -83,6 +83,7 @@ extern void yyerror __P((char *, ...))
static struct cf_namelist *iflist_head, *hostlist_head, *iapdlist_head;
struct cf_list *cf_dns_list, *cf_dns_name_list, *cf_ntp_list;
struct cf_list *cf_sip_list, *cf_sip_name_list;
long long cf_lifetime = -1;

extern int yylex __P((void));
static void cleanup __P((void));
Expand All @@ -95,7 +96,7 @@ static void cleanup_cflist __P((struct cf_list *));
%token ID_ASSOC IA_PD IAID
%token REQUEST SEND ALLOW PREFERENCE
%token HOST HOSTNAME DUID
%token OPTION RAPID_COMMIT IA_PD DNS_SERVERS DNS_NAME NTP_SERVERS
%token OPTION RAPID_COMMIT IA_PD DNS_SERVERS DNS_NAME NTP_SERVERS LIFETIME
%token SIP_SERVERS SIP_NAME
%token INFO_ONLY
%token SCRIPT
Expand Down Expand Up @@ -212,6 +213,23 @@ option_statement:
cf_sip_name_list->tail = l->next;
}
}
| OPTION LIFETIME NUMBER EOS
{
if (cf_lifetime == -1) {
cf_lifetime = $3;
if (cf_lifetime < -1 ||
cf_lifetime > 0xffffffff) {
/*
* lifetime should not be negative
* according to the lex definition,
* but check it for safety.
*/
yyerror("lifetime is out of range");
}
} else {
yywarn("multiple lifetimes (ignored)");
}
}
;

ia_statement:
Expand Down Expand Up @@ -430,14 +448,22 @@ dhcpoption:
/* currently no value */
$$ = l;
}
| NTP_SERVERS
| NTP_SERVERS
{
struct cf_list *l;

MAKE_CFLIST(l, DHCPOPT_NTP, NULL, NULL);
/* currently no value */
$$ = l;
}
| LIFETIME
{
struct cf_list *l;

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

prefixparam:
Expand Down
3 changes: 2 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.28 2004/01/20 07:24:44 suz Exp $ */
/* $KAME: cftoken.l,v 1.29 2004/03/21 14:40:51 jinmei Exp $ */

%{
/*
Expand Down Expand Up @@ -162,6 +162,7 @@ ecl \}
<S_CNF>sip-server-address { DECHO; return (SIP_SERVERS); }
<S_CNF>sip-server-domain-name { DECHO; return (SIP_NAME); }
<S_CNF>ntp-servers { DECHO; return (NTP_SERVERS); }
<S_CNF>lifetime { DECHO; return (LIFETIME); }
/* generic options */
<S_CNF>information-only { DECHO; return (INFO_ONLY); }
Expand Down
29 changes: 28 additions & 1 deletion kame/kame/dhcp6/common.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $KAME: common.c,v 1.96 2004/01/20 23:23:37 suz Exp $ */
/* $KAME: common.c,v 1.97 2004/03/21 14:40:51 jinmei Exp $ */
/*
* Copyright (C) 1998 and 1999 WIDE Project.
* All rights reserved.
Expand Down Expand Up @@ -874,6 +874,7 @@ dhcp6_init_options(optinfo)

optinfo->pref = DH6OPT_PREF_UNDEF;
optinfo->elapsed_time = DH6OPT_ELAPSED_TIME_UNDEF;
optinfo->lifetime = DH6OPT_LIFETIME_UNDEF;

TAILQ_INIT(&optinfo->iapd_list);
TAILQ_INIT(&optinfo->reqopt_list);
Expand Down Expand Up @@ -976,6 +977,7 @@ dhcp6_get_options(p, ep, optinfo)
u_int16_t num;
char *cp, *val;
u_int16_t val16;
u_int32_t val32;
struct dhcp6opt_ia optia;
struct dhcp6_ia ia;
struct dhcp6_list sublist;
Expand Down Expand Up @@ -1284,6 +1286,18 @@ dhcp6_get_options(p, ep, optinfo)
if (get_delegated_prefixes(cp, cp + optlen, optinfo))
goto fail;
break;
case DH6OPT_LIFETIME:
if (optlen != 4)
goto malformed;
memcpy(&val32, cp, sizeof(val32));
val32 = ntohl(val32);
dprintf(LOG_DEBUG, "", " lifetime: %lu", val32);
if (optinfo->lifetime != DH6OPT_LIFETIME_UNDEF) {
dprintf(LOG_INFO, FNAME,
"duplicated lifetime option");
} else
optinfo->lifetime = (int64_t)val32;
break;
default:
/* no option specific behavior */
dprintf(LOG_INFO, FNAME,
Expand Down Expand Up @@ -1887,6 +1901,13 @@ dhcp6_set_options(bp, ep, optinfo)
optinfo->ifidopt_id, p);
}

if (optinfo->lifetime != DH6OPT_LIFETIME_UNDEF) {
u_int32_t p32 = (u_int32_t)optinfo->lifetime;

p32 = htonl(p32);
COPY_OPTION(DH6OPT_LIFETIME, sizeof(p32), &p32, p);
}

return (len);

fail:
Expand Down Expand Up @@ -2131,6 +2152,10 @@ dhcp6_reset_timer(ev)
* MUST be delayed by a random amount of time between
* 0 and SOL_MAX_DELAY.
* [RFC3315 17.1.2]
* XXX: a random delay is also necessary before the first
* information-request message. Fortunately, the parameters
* and the algorithm for these two cases are same.
* [RFC3315 18.1.5]
*/
ev->retrans = (random() % (SOL_MAX_DELAY));
break;
Expand Down Expand Up @@ -2267,6 +2292,8 @@ dhcp6optstr(type)
return ("IA_PD");
case DH6OPT_IA_PD_PREFIX:
return ("IA_PD prefix");
case DH6OPT_LIFETIME:
return ("Lifetime");
default:
snprintf(genstr, sizeof(genstr), "opt_%d", type);
return (genstr);
Expand Down
16 changes: 15 additions & 1 deletion kame/kame/dhcp6/config.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $KAME: config.c,v 1.37 2004/01/20 07:24:45 suz Exp $ */
/* $KAME: config.c,v 1.38 2004/03/21 14:40:51 jinmei Exp $ */

/*
* Copyright (C) 2002 WIDE Project.
Expand Down Expand Up @@ -51,11 +51,13 @@ extern int errno;

struct prefix_ifconf *prefix_ifconflist;
struct dhcp6_list siplist, sipnamelist, dnslist, dnsnamelist, ntplist;
long long optlifetime = -1;

static struct dhcp6_ifconf *dhcp6_ifconflist;
struct ia_conflist ia_conflist0;
static struct host_conf *host_conflist0, *host_conflist;
static struct dhcp6_list siplist0, sipnamelist0, dnslist0, dnsnamelist0, ntplist0;
static long long optlifetime0;

enum { DHCPOPTCODE_SEND, DHCPOPTCODE_REQUEST, DHCPOPTCODE_ALLOW };

Expand All @@ -79,6 +81,7 @@ struct dhcp6_ifconf {

extern struct cf_list *cf_dns_list, *cf_dns_name_list, *cf_ntp_list;
extern struct cf_list *cf_sip_list, *cf_sip_name_list;
extern long long cf_lifetime;
extern char *configfilename;

static int add_pd_pif __P((struct iapd_conf *, struct cf_list *));
Expand Down Expand Up @@ -617,6 +620,9 @@ configure_global_option()
}
}

/* Lifetime for stateless options */
optlifetime0 = cf_lifetime;

return (0);

bad:
Expand Down Expand Up @@ -760,6 +766,7 @@ configure_cleanup()
TAILQ_INIT(&dnsnamelist0);
dhcp6_clear_list(&ntplist0);
TAILQ_INIT(&ntplist0);
optlifetime0 = -1;
}

void
Expand Down Expand Up @@ -827,6 +834,9 @@ configure_commit()
/* commit NTP addresses */
dhcp6_clear_list(&ntplist);
dhcp6_move_list(&ntplist, &ntplist0);

/* commit option lifetime */
optlifetime = optlifetime0;
}

static void
Expand Down Expand Up @@ -978,6 +988,7 @@ add_options(opcode, ifc, cfl0)
case DHCPOPT_DNS:
case DHCPOPT_DNSNAME:
case DHCPOPT_NTP:
case DHCPOPT_LIFETIME:
switch (cfl->type) {
case DHCPOPT_SIP:
opttype = DH6OPT_SIP_SERVER_A;
Expand All @@ -994,6 +1005,9 @@ add_options(opcode, ifc, cfl0)
case DHCPOPT_NTP:
opttype = DH6OPT_NTP;
break;
case DHCPOPT_LIFETIME:
opttype = DH6OPT_LIFETIME;
break;
}
switch(opcode) {
case DHCPOPTCODE_REQUEST:
Expand Down
4 changes: 3 additions & 1 deletion kame/kame/dhcp6/config.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $KAME: config.h,v 1.27 2004/01/20 07:24:45 suz Exp $ */
/* $KAME: config.h,v 1.28 2004/03/21 14:40:51 jinmei Exp $ */

/*
* Copyright (C) 2002 WIDE Project.
Expand Down Expand Up @@ -195,6 +195,7 @@ enum {DECL_SEND, DECL_ALLOW, DECL_INFO_ONLY, DECL_REQUEST, DECL_DUID,
IFPARAM_SLA_ID, IFPARAM_SLA_LEN,
DHCPOPT_RAPID_COMMIT, DHCPOPT_DNS, DHCPOPT_DNSNAME,
DHCPOPT_IA_PD, DHCPOPT_NTP,
DHCPOPT_LIFETIME,
CFLISTENT_GENERIC,
IACONF_PIF, IACONF_PREFIX,
DHCPOPT_SIP, DHCPOPT_SIPNAME };
Expand All @@ -212,6 +213,7 @@ extern struct dhcp6_list sipnamelist;
extern struct dhcp6_list dnslist;
extern struct dhcp6_list dnsnamelist;
extern struct dhcp6_list ntplist;
extern long long optlifetime;

extern void ifinit __P((char *));
extern int configure_interface __P((struct cf_namelist *));
Expand Down
12 changes: 12 additions & 0 deletions kame/kame/dhcp6/configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@ else
fi
AC_SUBST(dhcpopt_ntp)

AC_MSG_CHECKING(for DHCP Lifetime option)
AC_ARG_WITH(opt-lifetime,
[ --with-opt-lifetime=VALUE specify DHCP option value for lifetime],
dhcpopt_lifetime="$withval", dhcpopt_lifetime=0)
if test $dhcpopt_ntp = 0 ; then
dhcpopt_ntp=36
AC_MSG_RESULT(unspecified and using $dhcpopt_lifetime)
else
AC_MSG_RESULT(using $dhcpopt_lifetime)
fi
AC_SUBST(dhcpopt_lifetime)

AC_CHECK_HEADERS(stdarg.h)

AC_OUTPUT(Makefile)
7 changes: 5 additions & 2 deletions kame/kame/dhcp6/dhcp6.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $KAME: dhcp6.h,v 1.46 2004/01/20 07:24:45 suz Exp $ */
/* $KAME: dhcp6.h,v 1.47 2004/03/21 14:40:51 jinmei Exp $ */
/*
* Copyright (C) 1998 and 1999 WIDE Project.
* All rights reserved.
Expand Down Expand Up @@ -145,6 +145,7 @@ struct dhcp6_optinfo {
int rapidcommit; /* bool */
int pref; /* server preference */
int32_t elapsed_time; /* elapsed time (from client to server only) */
int64_t lifetime; /* lifetime for stateless options */

struct dhcp6_list iapd_list; /* list of IA_PD */
struct dhcp6_list reqopt_list; /* options in option request */
Expand Down Expand Up @@ -251,8 +252,10 @@ struct dhcp6_relay {
#define DH6OPT_PREFIX_INFORMATION CONF_DH6OPT_PREFIX_INFORMATION
#define DH6OPT_PREFIX_REQUEST CONF_DH6OPT_PREFIX_REQUEST

/* The following one is KAME specific. */
/* The followings are KAME specific. */
#define DH6OPT_NTP CONF_DH6OPT_NTP
#define DH6OPT_LIFETIME CONF_DH6OPT_LIFETIME
# define DH6OPT_LIFETIME_UNDEF -1

struct dhcp6opt {
u_int16_t dh6opt_type;
Expand Down
Loading

0 comments on commit 2e0e974

Please sign in to comment.