Tue Apr 21 12:16:47 2020 UTC ()
rtadvd: Remove disabled use of SIOCGIFPREFIX_IN6

It's not been enabled since the functionality was added to ifconfig(8)
many many years ago.


(roy)
diff -r1.43 -r1.44 src/usr.sbin/rtadvd/config.c
diff -r1.10 -r1.11 src/usr.sbin/rtadvd/config.h
diff -r1.72 -r1.73 src/usr.sbin/rtadvd/rtadvd.c

cvs diff -r1.43 -r1.44 src/usr.sbin/rtadvd/config.c (expand / switch to context diff)
--- src/usr.sbin/rtadvd/config.c 2019/11/11 13:42:49 1.43
+++ src/usr.sbin/rtadvd/config.c 2020/04/21 12:16:47 1.44
@@ -1,4 +1,4 @@
-/*	$NetBSD: config.c,v 1.43 2019/11/11 13:42:49 roy Exp $	*/
+/*	$NetBSD: config.c,v 1.44 2020/04/21 12:16:47 roy Exp $	*/
 /*	$KAME: config.c,v 1.93 2005/10/17 14:40:02 suz Exp $	*/
 
 /*
@@ -875,49 +875,6 @@
 }
 
 /*
- * Add a prefix to the list of specified interface and reconstruct
- * the outgoing packet.
- * The prefix must not be in the list.
- * XXX: other parameters of the prefix(e.g. lifetime) should be
- * able to be specified.
- */
-static void
-add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr)
-{
-	struct prefix *prefix;
-	char ntopbuf[INET6_ADDRSTRLEN];
-
-	if ((prefix = calloc(1, sizeof(*prefix))) == NULL) {
-		logit(LOG_ERR, "<%s> memory allocation failed",
-		       __func__);
-		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->origin = PREFIX_FROM_DYNAMIC;
-
-	prefix->rainfo = rai;
-	TAILQ_INSERT_TAIL(&rai->prefix, prefix, next);
-	rai->pfxs++;
-
-	logit(LOG_DEBUG, "<%s> new prefix %s/%d was added on %s",
-	       __func__, inet_ntop(AF_INET6, &ipr->ipr_prefix.sin6_addr,
-				       ntopbuf, INET6_ADDRSTRLEN),
-	       ipr->ipr_plen, rai->ifname);
-
-	/* free the previous packet */
-	free(rai->ra_data);
-	rai->ra_data = NULL;
-
-	/* reconstruct the packet */
-	make_packet(rai);
-}
-
-/*
  * Delete a prefix to the list of specified interface and reconstruct
  * the outgoing packet.
  * The prefix must be in the list.
@@ -1001,73 +958,45 @@
 }
 
 /*
- * 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[].
+ * Add a prefix to the list of specified interface and reconstruct
+ * the outgoing packet.
+ * The prefix must not be in the list.
+ * XXX: other parameters of the prefix(e.g. lifetime) should be
+ * able to be specified.
  */
-static int
-init_prefix(struct in6_prefixreq *ipr)
+void
+add_prefix(struct rainfo *rai, int ifindex, struct in6_addr *addr, int plen)
 {
-#if 0
-	int s;
+	struct prefix *prefix;
+	char ntopbuf[INET6_ADDRSTRLEN];
 
-	if ((s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
-		logit(LOG_ERR, "<%s> socket: %m", __func__);
-		exit(1);
+	if ((prefix = calloc(1, sizeof(*prefix))) == NULL) {
+		logit(LOG_ERR, "<%s> memory allocation failed",
+		       __func__);
+		return;		/* XXX: error or exit? */
 	}
+	prefix->prefix = *addr;
+	prefix->prefixlen = plen;
+	prefix->validlifetime = DEF_ADVVALIDLIFETIME;
+	prefix->preflifetime = DEF_ADVPREFERREDLIFETIME;
+	prefix->onlinkflg = 1;
+	prefix->autoconfflg = 0;
+	prefix->origin = PREFIX_FROM_DYNAMIC;
 
-	if (prog_ioctl(s, SIOCGIFPREFIX_IN6, ipr) < 0) {
-		logit(LOG_INFO, "<%s> ioctl:SIOCGIFPREFIX: %m", __func__);
+	prefix->rainfo = rai;
+	TAILQ_INSERT_TAIL(&rai->prefix, prefix, next);
+	rai->pfxs++;
 
-		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) {
-		char ntopbuf[INET6_ADDRSTRLEN];
+	logit(LOG_DEBUG, "<%s> new prefix %s/%d was added on %s",
+	       __func__, inet_ntop(AF_INET6, addr, ntopbuf, INET6_ADDRSTRLEN),
+	       plen, rai->ifname);
 
-		logit(LOG_WARNING, "<%s> Added prefix(%s)'s origin %d is"
-		       "lower than PR_ORIG_RR(router renumbering)."
-		       "This should not happen if I am router", __func__,
-		       inet_ntop(AF_INET6, &ipr->ipr_prefix.sin6_addr, ntopbuf,
-				 sizeof(ntopbuf)), ipr->ipr_origin);
-		prog_close(s);
-		return 1;
-	}
+	/* free the previous packet */
+	free(rai->ra_data);
+	rai->ra_data = NULL;
 
-	prog_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
-make_prefix(struct rainfo *rai, int ifindex, struct in6_addr *addr, int plen)
-{
-	struct in6_prefixreq ipr;
-
-	memset(&ipr, 0, sizeof(ipr));
-	if (if_indextoname(ifindex, ipr.ipr_name) == NULL) {
-		logit(LOG_ERR, "<%s> Prefix added interface No.%d doesn't"
-		       "exist. This should not happen: %m", __func__,
-		       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;
-
-	if (init_prefix(&ipr))
-		return; /* init failed by some error */
-	add_prefix(rai, &ipr);
+	/* reconstruct the packet */
+	make_packet(rai);
 }
 
 void

cvs diff -r1.10 -r1.11 src/usr.sbin/rtadvd/config.h (expand / switch to context diff)
--- src/usr.sbin/rtadvd/config.h 2018/04/20 10:39:37 1.10
+++ src/usr.sbin/rtadvd/config.h 2020/04/21 12:16:47 1.11
@@ -1,4 +1,4 @@
-/*	$NetBSD: config.h,v 1.10 2018/04/20 10:39:37 roy Exp $	*/
+/*	$NetBSD: config.h,v 1.11 2020/04/21 12:16:47 roy Exp $	*/
 /*	$KAME: config.h,v 1.9 2003/08/06 04:19:40 ono Exp $	*/
 
 /*
@@ -35,7 +35,7 @@
 extern void delete_prefix(struct prefix *);
 extern void invalidate_prefix(struct prefix *);
 extern void update_prefix(struct prefix *);
-extern void make_prefix(struct rainfo *, int, struct in6_addr *, int);
+extern void add_prefix(struct rainfo *, int, struct in6_addr *, int);
 extern void make_packet(struct rainfo *);
 extern void get_prefix(struct rainfo *);
 

cvs diff -r1.72 -r1.73 src/usr.sbin/rtadvd/rtadvd.c (expand / switch to context diff)
--- src/usr.sbin/rtadvd/rtadvd.c 2020/04/21 12:05:54 1.72
+++ src/usr.sbin/rtadvd/rtadvd.c 2020/04/21 12:16:47 1.73
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtadvd.c,v 1.72 2020/04/21 12:05:54 roy Exp $	*/
+/*	$NetBSD: rtadvd.c,v 1.73 2020/04/21 12:16:47 roy Exp $	*/
 /*	$KAME: rtadvd.c,v 1.92 2005/10/17 14:40:02 suz Exp $	*/
 
 /*
@@ -615,7 +615,7 @@
 				}
 				break;
 			}
-			make_prefix(rai, ifindex, addr, plen);
+			add_prefix(rai, ifindex, addr, plen);
 			prefixchange = 1;
 			break;
 		case RTM_DELETE: