From c71b648fce03487bba12630b8c5fdf5fbc9ee55d Mon Sep 17 00:00:00 2001 From: marjohn56 Date: Thu, 15 Dec 2016 19:58:55 +0000 Subject: [PATCH] dhcp6c no release option & extra light info logging Add a no release option '-n'. This prevents a release signal from being sent to the ISP causing a new PD or address to be allocated. Added some extra light INFO logging which is useful to see the communications between dhcp6c and the ISP --- net/dhcp6/files/patch-common.h | 9 +++ net/dhcp6/files/patch-dhcp6c.c | 118 +++++++++++++++++++++++++++-- net/dhcp6/files/patch-dhcp6c__ia.c | 16 ++++ net/dhcp6/files/patch-prefixconf.c | 11 +++ 4 files changed, 146 insertions(+), 8 deletions(-) create mode 100644 net/dhcp6/files/patch-dhcp6c__ia.c create mode 100644 net/dhcp6/files/patch-prefixconf.c diff --git a/net/dhcp6/files/patch-common.h b/net/dhcp6/files/patch-common.h index cf1187f71417..5bcfc233220d 100644 --- a/net/dhcp6/files/patch-common.h +++ b/net/dhcp6/files/patch-common.h @@ -9,3 +9,12 @@ extern int get_duid __P((char *, struct duid *)); extern void dhcp6_init_options __P((struct dhcp6_optinfo *)); extern void dhcp6_clear_options __P((struct dhcp6_optinfo *)); +@@ -179,7 +179,7 @@ extern void duidfree __P((struct duid *) + extern int ifaddrconf __P((ifaddrconf_cmd_t, char *, struct sockaddr_in6 *, + int, int, int)); + extern int safefile __P((const char *)); +- ++extern int opt_norelease; + /* missing */ + #ifndef HAVE_STRLCAT + extern size_t strlcat __P((char *, const char *, size_t)); diff --git a/net/dhcp6/files/patch-dhcp6c.c b/net/dhcp6/files/patch-dhcp6c.c index d86fcbf55790..61bdbb87703b 100644 --- a/net/dhcp6/files/patch-dhcp6c.c +++ b/net/dhcp6/files/patch-dhcp6c.c @@ -16,7 +16,43 @@ int ctlsock = -1; /* control TCP port */ char *ctladdr = DEFAULT_CLIENT_CONTROL_ADDR; char *ctlport = DEFAULT_CLIENT_CONTROL_PORT; -@@ -257,7 +257,7 @@ client6_init() +@@ -147,6 +147,7 @@ int client6_start __P((struct dhcp6_if * + static void info_printf __P((const char *, ...)); + + extern int client6_script __P((char *, int, struct dhcp6_optinfo *)); ++int opt_norelease; + + #define MAX_ELAPSED_TIME 0xffff + +@@ -169,7 +170,7 @@ main(argc, argv) + else + progname++; + +- while ((ch = getopt(argc, argv, "c:dDfik:p:")) != -1) { ++ while ((ch = getopt(argc, argv, "c:ndDfik:p:")) != -1) { + switch (ch) { + case 'c': + conffile = optarg; +@@ -192,6 +193,9 @@ main(argc, argv) + case 'p': + pid_file = optarg; + break; ++ case 'n': ++ opt_norelease = 1; ++ break; + default: + usage(); + exit(0); +@@ -246,7 +250,7 @@ static void + usage() + { + +- fprintf(stderr, "usage: dhcp6c [-c configfile] [-dDfi] " ++ fprintf(stderr, "usage: dhcp6c [-c configfile] [-ndDfi] " + "[-p pid-file] interface [interfaces...]\n"); + } + +@@ -257,7 +261,7 @@ client6_init() { struct addrinfo hints, *res; static struct sockaddr_in6 sa6_allagent_storage; @@ -25,7 +61,7 @@ /* get our DUID */ if (get_duid(DUID_FILE, &client_duid)) { -@@ -287,6 +287,20 @@ client6_init() +@@ -287,6 +291,20 @@ client6_init() dprintf(LOG_ERR, FNAME, "socket"); exit(1); } @@ -46,7 +82,7 @@ if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on)) < 0) { dprintf(LOG_ERR, FNAME, -@@ -337,13 +351,6 @@ client6_init() +@@ -337,13 +355,6 @@ client6_init() } freeaddrinfo(res); @@ -60,7 +96,7 @@ memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_INET6; hints.ai_socktype = SOCK_DGRAM; -@@ -596,7 +603,7 @@ get_ifname(bpp, lenp, ifbuf, ifbuflen) +@@ -596,7 +607,7 @@ get_ifname(bpp, lenp, ifbuf, ifbuflen) if (*lenp < ifnamelen || ifnamelen > ifbuflen) return (-1); @@ -69,7 +105,7 @@ memcpy(ifbuf, *bpp, ifnamelen); if (ifbuf[ifbuflen - 1] != '\0') return (-1); /* not null terminated */ -@@ -763,6 +770,15 @@ client6_ifctl(ifname, command) +@@ -763,6 +774,15 @@ client6_ifctl(ifname, command) switch(command) { case DHCP6CTL_COMMAND_START: @@ -85,7 +121,7 @@ free_resources(ifp); if (client6_start(ifp)) { dprintf(LOG_NOTICE, FNAME, "failed to restart %s", -@@ -929,7 +945,7 @@ construct_confdata(ifp, ev) +@@ -929,7 +949,7 @@ construct_confdata(ifp, ev) "failed to create a new event data"); goto fail; } @@ -94,7 +130,73 @@ memset(&iaparam, 0, sizeof(iaparam)); iaparam.iaid = iac->iaid; -@@ -1828,15 +1844,6 @@ client6_recvreply(ifp, dh6, len, optinfo +@@ -1163,27 +1183,33 @@ client6_send(ev) + switch(ev->state) { + case DHCP6S_SOLICIT: + dh6->dh6_msgtype = DH6_SOLICIT; ++ d_printf(LOG_INFO, FNAME, "Sending Solicit"); + break; + case DHCP6S_REQUEST: + dh6->dh6_msgtype = DH6_REQUEST; ++ d_printf(LOG_INFO, FNAME, "Sending Request"); + break; + case DHCP6S_RENEW: + dh6->dh6_msgtype = DH6_RENEW; ++ d_printf(LOG_INFO, FNAME, "Sending Renew"); + break; + case DHCP6S_REBIND: + dh6->dh6_msgtype = DH6_REBIND; ++ d_printf(LOG_INFO, FNAME, "Sending Rebind"); + break; + case DHCP6S_RELEASE: + dh6->dh6_msgtype = DH6_RELEASE; ++ d_printf(LOG_INFO, FNAME, "Sending Release"); + break; + case DHCP6S_INFOREQ: + dh6->dh6_msgtype = DH6_INFORM_REQ; ++ d_printf(LOG_INFO, FNAME, "Sending Information Request"); + break; + default: + dprintf(LOG_ERR, FNAME, "unexpected state"); + exit(1); /* XXX */ + } +- ++ + if (ev->timeouts == 0) { + /* + * A client SHOULD generate a random number that cannot easily +@@ -1721,7 +1747,29 @@ client6_recvreply(ifp, dh6, len, optinfo + dprintf(LOG_INFO, FNAME, "unexpected reply"); + return (-1); + } +- ++ ++ switch(state) ++ { ++ case DHCP6S_INFOREQ: ++ d_printf(LOG_INFO, FNAME, "dhcp6c Received INFOREQ"); ++ break; ++ case DHCP6S_REQUEST: ++ d_printf(LOG_INFO, FNAME, "dhcp6c Received REQUEST"); ++ break; ++ case DHCP6S_RENEW: ++ d_printf(LOG_INFO, FNAME, "dhcp6c Received INFO"); ++ break; ++ case DHCP6S_REBIND: ++ d_printf(LOG_INFO, FNAME, "dhcp6c Received REBIND"); ++ break; ++ case DHCP6S_RELEASE: ++ d_printf(LOG_INFO, FNAME, "dhcp6c Received RELEASE"); ++ break; ++ case DHCP6S_SOLICIT: ++ d_printf(LOG_INFO, FNAME, "dhcp6c Received SOLICIT"); ++ break; ++ } ++ + /* A Reply message must contain a Server ID option */ + if (optinfo->serverID.duid_len == 0) { + dprintf(LOG_INFO, FNAME, "no server ID option"); +@@ -1828,15 +1876,6 @@ client6_recvreply(ifp, dh6, len, optinfo } /* @@ -110,7 +212,7 @@ * Set refresh timer for configuration information specified in * information-request. If the timer value is specified by the server * in an information refresh time option, use it; use the protocol -@@ -1888,6 +1895,15 @@ client6_recvreply(ifp, dh6, len, optinfo +@@ -1888,6 +1927,15 @@ client6_recvreply(ifp, dh6, len, optinfo &optinfo->serverID, ev->authparam); } diff --git a/net/dhcp6/files/patch-dhcp6c__ia.c b/net/dhcp6/files/patch-dhcp6c__ia.c new file mode 100644 index 000000000000..8a48a6085356 --- /dev/null +++ b/net/dhcp6/files/patch-dhcp6c__ia.c @@ -0,0 +1,16 @@ +--- dhcp6c_ia.c.orig 2007-03-21 09:52:55 UTC ++++ dhcp6c_ia.c +@@ -420,7 +420,12 @@ release_all_ia(ifp) + for (ia = TAILQ_FIRST(&iac->iadata); ia; ia = ia_next) { + ia_next = TAILQ_NEXT(ia, link); + +- (void)release_ia(ia); ++ if(opt_norelease != 1){ ++ d_printf(LOG_INFO, FNAME,"Start address release"); ++ (void)release_ia(ia); ++ } else { ++ d_printf(LOG_INFO,FNAME,"Bypassing address release"); ++ } + + /* + * The client MUST stop using all of the addresses diff --git a/net/dhcp6/files/patch-prefixconf.c b/net/dhcp6/files/patch-prefixconf.c new file mode 100644 index 000000000000..129d5cfd0716 --- /dev/null +++ b/net/dhcp6/files/patch-prefixconf.c @@ -0,0 +1,11 @@ +--- prefixconf.c.orig 2007-03-21 09:52:55 UTC ++++ prefixconf.c +@@ -192,7 +192,7 @@ update_prefix(ia, pinfo, pifc, dhcpifp, + /* update the prefix according to pinfo */ + sp->prefix.pltime = pinfo->pltime; + sp->prefix.vltime = pinfo->vltime; +- dprintf(LOG_DEBUG, FNAME, "%s a prefix %s/%d pltime=%lu, vltime=%lu", ++ d_printf(LOG_INFO, FNAME, "%s a prefix %s/%d pltime=%lu, vltime=%lu", + spcreate ? "create" : "update", + in6addr2str(&pinfo->addr, 0), pinfo->plen, + pinfo->pltime, pinfo->vltime);