Re: rtadvd: remove more dead code

2016-02-28 Thread Jeremie Courreges-Anglas
j...@wxcvbn.org (Jeremie Courreges-Anglas) writes:

> j...@wxcvbn.org (Jeremie Courreges-Anglas) writes:
>
>> Alexander Bluhm  writes:
>>
>>> On Tue, Feb 09, 2016 at 02:17:18AM +0100, J??r??mie Courr??ges-Anglas wrote:
 
 - a few *cnt members of struct rainfo aren't used for anything
 - the SIOCGIFPREFIX_IN6 ioctl has been deprecated since June 2002
 - prefix_match() and in6a_site_allrouters are remnants from the
   Renumbering code (now in the Attic)
 
 ok?
>>>
>>> OK bluhm@
>>>
>>> I think you should also kill the function init_prefix() and move
>>> the remaining 4 lines into make_prefix() in another diff.
>>
>> duh, thanks.  Here's the diff:

Committed,

> The next diff will merge make_prefix/add_prefix and kill the use of
> "struct in6_prefixreq"... in rtadvd.

Index: config.c
===
RCS file: /cvs/src/usr.sbin/rtadvd/config.c,v
retrieving revision 1.53
diff -u -p -r1.53 config.c
--- config.c29 Feb 2016 06:37:55 -  1.53
+++ config.c29 Feb 2016 06:40:21 -
@@ -618,8 +618,8 @@ makeentry(char *buf, size_t len, int id,
  * XXX: other parameters of the prefix (e.g. lifetime) ought
  * to be specified.
  */
-static void
-add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr)
+void
+make_prefix(struct rainfo *rai, int ifindex, struct in6_addr *addr, int plen)
 {
struct prefix *prefix;
u_char ntopbuf[INET6_ADDRSTRLEN];
@@ -628,20 +628,20 @@ add_prefix(struct rainfo *rai, struct in
log_warn("calloc");
return; /* XXX: error or exit? */
}
-   prefix->prefix = ipr->ipr_prefix.sin6_addr;
-   prefix->prefixlen = ipr->ipr_plen;
-   prefix->validlifetime = ipr->ipr_vltime;
-   prefix->preflifetime = ipr->ipr_pltime;
-   prefix->onlinkflg = ipr->ipr_raf_onlink;
-   prefix->autoconfflg = ipr->ipr_raf_auto;
+   prefix->prefix = *addr;
+   prefix->prefixlen = plen;
+   prefix->validlifetime = DEF_ADVVALIDLIFETIME;
+   prefix->preflifetime = DEF_ADVPREFERREDLIFETIME;
+   prefix->onlinkflg = 1;
+   prefix->autoconfflg = 1;
prefix->origin = PREFIX_FROM_DYNAMIC;
 
TAILQ_INSERT_TAIL(>prefixes, prefix, entry);
 
log_debug("new prefix %s/%d was added on %s",
-   inet_ntop(AF_INET6, >ipr_prefix.sin6_addr,
+   inet_ntop(AF_INET6, >prefix,
   ntopbuf, INET6_ADDRSTRLEN),
-   ipr->ipr_plen, rai->ifname);
+   prefix->prefixlen, rai->ifname);
 
/* free the previous packet */
free(rai->ra_data);
@@ -676,29 +676,6 @@ delete_prefix(struct rainfo *rai, struct
free(prefix);
rai->pfxs--;
make_packet(rai);
-}
-
-void
-make_prefix(struct rainfo *rai, int ifindex, struct in6_addr *addr, int plen)
-{
-   struct in6_prefixreq ipr;
-
-   memset(, 0, sizeof(ipr));
-   if (if_indextoname(ifindex, ipr.ipr_name) == NULL) {
-   log_warn("Prefix added interface No.%d doesn't"
-   " exist. This should not happen!", ifindex);
-   exit(1);
-   }
-   ipr.ipr_prefix.sin6_len = sizeof(ipr.ipr_prefix);
-   ipr.ipr_prefix.sin6_family = AF_INET6;
-   ipr.ipr_prefix.sin6_addr = *addr;
-   ipr.ipr_plen = plen;
-   ipr.ipr_vltime = DEF_ADVVALIDLIFETIME;
-   ipr.ipr_pltime = DEF_ADVPREFERREDLIFETIME;
-   ipr.ipr_raf_onlink = 1;
-   ipr.ipr_raf_auto = 1;
-
-   add_prefix(rai, );
 }
 
 void


-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: rtadvd: remove more dead code

2016-02-28 Thread Alexander Bluhm
On Sun, Feb 28, 2016 at 12:16:12AM +0100, Jeremie Courreges-Anglas wrote:
> Alexander Bluhm  writes:
> > OK bluhm@
> >
> > I think you should also kill the function init_prefix() and move
> > the remaining 4 lines into make_prefix() in another diff.
> 
> duh, thanks.  Here's the diff:

OK bluhm@

> 
> Index: config.c
> ===
> RCS file: /cvs/src/usr.sbin/rtadvd/config.c,v
> retrieving revision 1.52
> diff -u -p -r1.52 config.c
> --- config.c  26 Feb 2016 12:33:30 -  1.52
> +++ config.c  27 Feb 2016 23:13:29 -
> @@ -678,21 +678,6 @@ delete_prefix(struct rainfo *rai, struct
>   make_packet(rai);
>  }
>  
> -/*
> - * Try to get an in6_prefixreq contents for a prefix which matches
> - * ipr->ipr_prefix and ipr->ipr_plen and belongs to
> - * the interface whose name is ipr->ipr_name[].
> - */
> -static int
> -init_prefix(struct in6_prefixreq *ipr)
> -{
> - ipr->ipr_vltime = DEF_ADVVALIDLIFETIME;
> - ipr->ipr_pltime = DEF_ADVPREFERREDLIFETIME;
> - ipr->ipr_raf_onlink = 1;
> - ipr->ipr_raf_auto = 1;
> - return 0;
> -}
> -
>  void
>  make_prefix(struct rainfo *rai, int ifindex, struct in6_addr *addr, int plen)
>  {
> @@ -708,9 +693,11 @@ make_prefix(struct rainfo *rai, int ifin
>   ipr.ipr_prefix.sin6_family = AF_INET6;
>   ipr.ipr_prefix.sin6_addr = *addr;
>   ipr.ipr_plen = plen;
> + ipr.ipr_vltime = DEF_ADVVALIDLIFETIME;
> + ipr.ipr_pltime = DEF_ADVPREFERREDLIFETIME;
> + ipr.ipr_raf_onlink = 1;
> + ipr.ipr_raf_auto = 1;
>  
> - if (init_prefix())
> - return; /* init failed by some error */
>   add_prefix(rai, );
>  }
>  
> 
> 
> -- 
> jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: rtadvd: remove more dead code

2016-02-28 Thread Jeremie Courreges-Anglas
j...@wxcvbn.org (Jeremie Courreges-Anglas) writes:

> Alexander Bluhm  writes:
>
>> On Tue, Feb 09, 2016 at 02:17:18AM +0100, J??r??mie Courr??ges-Anglas wrote:
>>> 
>>> - a few *cnt members of struct rainfo aren't used for anything
>>> - the SIOCGIFPREFIX_IN6 ioctl has been deprecated since June 2002
>>> - prefix_match() and in6a_site_allrouters are remnants from the
>>>   Renumbering code (now in the Attic)
>>> 
>>> ok?
>>
>> OK bluhm@
>>
>> I think you should also kill the function init_prefix() and move
>> the remaining 4 lines into make_prefix() in another diff.
>
> duh, thanks.  Here's the diff:

The next diff will merge make_prefix/add_prefix and kill the use of
"struct in6_prefixreq"... in rtadvd.

> Index: config.c
> ===
> RCS file: /cvs/src/usr.sbin/rtadvd/config.c,v
> retrieving revision 1.52
> diff -u -p -r1.52 config.c
> --- config.c  26 Feb 2016 12:33:30 -  1.52
> +++ config.c  27 Feb 2016 23:13:29 -
> @@ -678,21 +678,6 @@ delete_prefix(struct rainfo *rai, struct
>   make_packet(rai);
>  }
>  
> -/*
> - * Try to get an in6_prefixreq contents for a prefix which matches
> - * ipr->ipr_prefix and ipr->ipr_plen and belongs to
> - * the interface whose name is ipr->ipr_name[].
> - */
> -static int
> -init_prefix(struct in6_prefixreq *ipr)
> -{
> - ipr->ipr_vltime = DEF_ADVVALIDLIFETIME;
> - ipr->ipr_pltime = DEF_ADVPREFERREDLIFETIME;
> - ipr->ipr_raf_onlink = 1;
> - ipr->ipr_raf_auto = 1;
> - return 0;
> -}
> -
>  void
>  make_prefix(struct rainfo *rai, int ifindex, struct in6_addr *addr, int plen)
>  {
> @@ -708,9 +693,11 @@ make_prefix(struct rainfo *rai, int ifin
>   ipr.ipr_prefix.sin6_family = AF_INET6;
>   ipr.ipr_prefix.sin6_addr = *addr;
>   ipr.ipr_plen = plen;
> + ipr.ipr_vltime = DEF_ADVVALIDLIFETIME;
> + ipr.ipr_pltime = DEF_ADVPREFERREDLIFETIME;
> + ipr.ipr_raf_onlink = 1;
> + ipr.ipr_raf_auto = 1;
>  
> - if (init_prefix())
> - return; /* init failed by some error */
>   add_prefix(rai, );
>  }


-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: rtadvd: remove more dead code

2016-02-27 Thread Jeremie Courreges-Anglas
Alexander Bluhm  writes:

> On Tue, Feb 09, 2016 at 02:17:18AM +0100, J??r??mie Courr??ges-Anglas wrote:
>> 
>> - a few *cnt members of struct rainfo aren't used for anything
>> - the SIOCGIFPREFIX_IN6 ioctl has been deprecated since June 2002
>> - prefix_match() and in6a_site_allrouters are remnants from the
>>   Renumbering code (now in the Attic)
>> 
>> ok?
>
> OK bluhm@
>
> I think you should also kill the function init_prefix() and move
> the remaining 4 lines into make_prefix() in another diff.

duh, thanks.  Here's the diff:

Index: config.c
===
RCS file: /cvs/src/usr.sbin/rtadvd/config.c,v
retrieving revision 1.52
diff -u -p -r1.52 config.c
--- config.c26 Feb 2016 12:33:30 -  1.52
+++ config.c27 Feb 2016 23:13:29 -
@@ -678,21 +678,6 @@ delete_prefix(struct rainfo *rai, struct
make_packet(rai);
 }
 
-/*
- * Try to get an in6_prefixreq contents for a prefix which matches
- * ipr->ipr_prefix and ipr->ipr_plen and belongs to
- * the interface whose name is ipr->ipr_name[].
- */
-static int
-init_prefix(struct in6_prefixreq *ipr)
-{
-   ipr->ipr_vltime = DEF_ADVVALIDLIFETIME;
-   ipr->ipr_pltime = DEF_ADVPREFERREDLIFETIME;
-   ipr->ipr_raf_onlink = 1;
-   ipr->ipr_raf_auto = 1;
-   return 0;
-}
-
 void
 make_prefix(struct rainfo *rai, int ifindex, struct in6_addr *addr, int plen)
 {
@@ -708,9 +693,11 @@ make_prefix(struct rainfo *rai, int ifin
ipr.ipr_prefix.sin6_family = AF_INET6;
ipr.ipr_prefix.sin6_addr = *addr;
ipr.ipr_plen = plen;
+   ipr.ipr_vltime = DEF_ADVVALIDLIFETIME;
+   ipr.ipr_pltime = DEF_ADVPREFERREDLIFETIME;
+   ipr.ipr_raf_onlink = 1;
+   ipr.ipr_raf_auto = 1;
 
-   if (init_prefix())
-   return; /* init failed by some error */
add_prefix(rai, );
 }
 


-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: rtadvd: remove more dead code

2016-02-26 Thread Alexander Bluhm
On Tue, Feb 09, 2016 at 02:17:18AM +0100, J??r??mie Courr??ges-Anglas wrote:
> 
> - a few *cnt members of struct rainfo aren't used for anything
> - the SIOCGIFPREFIX_IN6 ioctl has been deprecated since June 2002
> - prefix_match() and in6a_site_allrouters are remnants from the
>   Renumbering code (now in the Attic)
> 
> ok?

OK bluhm@

I think you should also kill the function init_prefix() and move
the remaining 4 lines into make_prefix() in another diff.

bluhm



Re: rtadvd: remove more dead code

2016-02-25 Thread Jérémie Courrèges-Anglas
j...@wxcvbn.org (Jérémie Courrèges-Anglas) writes:

> - a few *cnt members of struct rainfo aren't used for anything
> - the SIOCGIFPREFIX_IN6 ioctl has been deprecated since June 2002
> - prefix_match() and in6a_site_allrouters are remnants from the
>   Renumbering code (now in the Attic)
>
> ok?

ping

> Index: config.c
> ===
> RCS file: /cvs/src/usr.sbin/rtadvd/config.c,v
> retrieving revision 1.50
> diff -u -p -r1.50 config.c
> --- config.c  9 Feb 2016 00:39:13 -   1.50
> +++ config.c  9 Feb 2016 00:54:13 -
> @@ -323,7 +323,6 @@ getconfig(char *intface)
>   if (tmp->pfxs == 0 && !agetflag("noifprefix"))
>   get_prefix(tmp);
>  
> - tmp->rtinfocnt = 0;
>   for (i = -1; i < MAXRTINFO; i++) {
>   struct rtinfo *rti;
>   char entbuf[256];
> @@ -391,10 +390,8 @@ getconfig(char *intface)
>   rti->lifetime = (uint32_t)val64;
>  
>   TAILQ_INSERT_TAIL(>rtinfos, rti, entry);
> - tmp->rtinfocnt++;
>   }
>  
> - tmp->rdnsscnt = 0;
>   for (i = -1; i < MAXRDNSS; ++i) {
>   struct rdnss *rds;
>   char entbuf[256];
> @@ -417,7 +414,6 @@ getconfig(char *intface)
>   fatal("malloc");
>  
>   TAILQ_INSERT_TAIL(>rdnsss, rds, entry);
> - tmp->rdnsscnt++;
>  
>   rds->servercnt = val;
>  
> @@ -441,7 +437,6 @@ getconfig(char *intface)
>   }
>   }
>  
> - tmp->dnsslcnt = 0;
>   for (i = -1; i < MAXDNSSL; ++i) {
>   struct dnssl *dsl;
>   char entbuf[256];
> @@ -481,7 +476,6 @@ getconfig(char *intface)
>   }
>  
>   TAILQ_INSERT_TAIL(>dnssls, dsl, entry);
> - tmp->dnsslcnt++;
>  
>   makeentry(entbuf, sizeof(entbuf), i, "dnsslltime");
>   MAYHAVE(val, entbuf, (tmp->maxinterval * 3) / 2);
> @@ -692,44 +686,11 @@ delete_prefix(struct rainfo *rai, struct
>  static int
>  init_prefix(struct in6_prefixreq *ipr)
>  {
> -#if 0
> - int s;
> -
> - if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
> - log_warn("socket");
> - exit(1);
> - }
> -
> - if (ioctl(s, SIOCGIFPREFIX_IN6, (caddr_t)ipr) < 0) {
> - log_warn("ioctl:SIOCGIFFLAGS: failed for %s", ifr.ifr_name);
> -
> - ipr->ipr_vltime = DEF_ADVVALIDLIFETIME;
> - ipr->ipr_pltime = DEF_ADVPREFERREDLIFETIME;
> - ipr->ipr_raf_onlink = 1;
> - ipr->ipr_raf_auto = 1;
> - /* omit other field initialization */
> - }
> - else if (ipr->ipr_origin < PR_ORIG_RR) {
> - u_char ntopbuf[INET6_ADDRSTRLEN];
> -
> - log_warn("Added prefix(%s)'s origin %d is"
> - " lower than PR_ORIG_RR(router renumbering)."
> - " This should not happen if I am router",
> - inet_ntop(AF_INET6, >ipr_prefix.sin6_addr, ntopbuf,
> - sizeof(ntopbuf)), ipr->ipr_origin);
> - close(s);
> - return 1;
> - }
> -
> - close(s);
> - return 0;
> -#else
>   ipr->ipr_vltime = DEF_ADVVALIDLIFETIME;
>   ipr->ipr_pltime = DEF_ADVPREFERREDLIFETIME;
>   ipr->ipr_raf_onlink = 1;
>   ipr->ipr_raf_auto = 1;
>   return 0;
> -#endif
>  }
>  
>  void
> Index: rtadvd.c
> ===
> RCS file: /cvs/src/usr.sbin/rtadvd/rtadvd.c,v
> retrieving revision 1.68
> diff -u -p -r1.68 rtadvd.c
> --- rtadvd.c  9 Feb 2016 00:40:00 -   1.68
> +++ rtadvd.c  9 Feb 2016 00:54:13 -
> @@ -1009,30 +1009,6 @@ find_prefix(struct rainfo *rai, struct i
>   return(NULL);
>  }
>  
> -/* check if p0/plen0 matches p1/plen1; return 1 if matches, otherwise 0. */
> -int
> -prefix_match(struct in6_addr *p0, int plen0,
> -  struct in6_addr *p1, int plen1)
> -{
> - int bytelen, bitlen;
> - u_char bitmask;
> -
> - if (plen0 < plen1)
> - return(0);
> - bytelen = plen1 / 8;
> - bitlen = plen1 % 8;
> - bitmask = 0xff << (8 - bitlen);
> - if (memcmp((void *)p0, (void *)p1, bytelen))
> - return(0);
> - if (bitlen == 0 ||
> - ((p0->s6_addr[bytelen] & bitmask) ==
> -  (p1->s6_addr[bytelen] & bitmask))) {
> - return(1);
> - }
> -
> - return(0);
> -}
> -
>  static int
>  nd6_options(struct nd_opt_hdr *hdr, int limit,
>   union nd_opts *ndopts, u_int32_t optflags)
> Index: rtadvd.h
> ===
> RCS file: /cvs/src/usr.sbin/rtadvd/rtadvd.h,v
> retrieving revision 1.21
> diff -u -p -r1.21 rtadvd.h
> --- rtadvd.h  9 Feb 2016 00:39:13 -   1.21
> +++ rtadvd.h  9 Feb 2016 00:54:13 -
> @@ -148,11 +148,8 @@ struct   rainfo {
>   TAILQ_HEAD(prefixlist, prefix) prefixes; /* AdvPrefixList(link head) */
>   int pfxs;