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 unified 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,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: config.c,v 1.43 2019/11/11 13:42:49 roy Exp $ */ 1/* $NetBSD: config.c,v 1.44 2020/04/21 12:16:47 roy Exp $ */
2/* $KAME: config.c,v 1.93 2005/10/17 14:40:02 suz Exp $ */ 2/* $KAME: config.c,v 1.93 2005/10/17 14:40:02 suz Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1998 WIDE Project. 5 * Copyright (C) 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -865,69 +865,26 @@ get_prefix(struct rainfo *rai) @@ -865,69 +865,26 @@ get_prefix(struct rainfo *rai)
865} 865}
866 866
867static void 867static void
868makeentry(char *buf, size_t len, int id, const char *string) 868makeentry(char *buf, size_t len, int id, const char *string)
869{ 869{
870 870
871 if (id < 0) 871 if (id < 0)
872 strlcpy(buf, string, len); 872 strlcpy(buf, string, len);
873 else 873 else
874 snprintf(buf, len, "%s%d", string, id); 874 snprintf(buf, len, "%s%d", string, id);
875} 875}
876 876
877/* 877/*
878 * Add a prefix to the list of specified interface and reconstruct 
879 * the outgoing packet. 
880 * The prefix must not be in the list. 
881 * XXX: other parameters of the prefix(e.g. lifetime) should be 
882 * able to be specified. 
883 */ 
884static void 
885add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr) 
886{ 
887 struct prefix *prefix; 
888 char ntopbuf[INET6_ADDRSTRLEN]; 
889 
890 if ((prefix = calloc(1, sizeof(*prefix))) == NULL) { 
891 logit(LOG_ERR, "<%s> memory allocation failed", 
892 __func__); 
893 return; /* XXX: error or exit? */ 
894 } 
895 prefix->prefix = ipr->ipr_prefix.sin6_addr; 
896 prefix->prefixlen = ipr->ipr_plen; 
897 prefix->validlifetime = ipr->ipr_vltime; 
898 prefix->preflifetime = ipr->ipr_pltime; 
899 prefix->onlinkflg = ipr->ipr_raf_onlink; 
900 prefix->autoconfflg = ipr->ipr_raf_auto; 
901 prefix->origin = PREFIX_FROM_DYNAMIC; 
902 
903 prefix->rainfo = rai; 
904 TAILQ_INSERT_TAIL(&rai->prefix, prefix, next); 
905 rai->pfxs++; 
906 
907 logit(LOG_DEBUG, "<%s> new prefix %s/%d was added on %s", 
908 __func__, inet_ntop(AF_INET6, &ipr->ipr_prefix.sin6_addr, 
909 ntopbuf, INET6_ADDRSTRLEN), 
910 ipr->ipr_plen, rai->ifname); 
911 
912 /* free the previous packet */ 
913 free(rai->ra_data); 
914 rai->ra_data = NULL; 
915 
916 /* reconstruct the packet */ 
917 make_packet(rai); 
918} 
919 
920/* 
921 * Delete a prefix to the list of specified interface and reconstruct 878 * Delete a prefix to the list of specified interface and reconstruct
922 * the outgoing packet. 879 * the outgoing packet.
923 * The prefix must be in the list. 880 * The prefix must be in the list.
924 */ 881 */
925void 882void
926delete_prefix(struct prefix *prefix) 883delete_prefix(struct prefix *prefix)
927{ 884{
928 char ntopbuf[INET6_ADDRSTRLEN]; 885 char ntopbuf[INET6_ADDRSTRLEN];
929 struct rainfo *rai = prefix->rainfo; 886 struct rainfo *rai = prefix->rainfo;
930 887
931 TAILQ_REMOVE(&rai->prefix, prefix, next); 888 TAILQ_REMOVE(&rai->prefix, prefix, next);
932 rai->pfxs--; 889 rai->pfxs--;
933 logit(LOG_DEBUG, "<%s> prefix %s/%d was deleted on %s", 890 logit(LOG_DEBUG, "<%s> prefix %s/%d was deleted on %s",
@@ -991,93 +948,65 @@ update_prefix(struct prefix * prefix) @@ -991,93 +948,65 @@ update_prefix(struct prefix * prefix)
991 __func__); 948 __func__);
992 exit(1); 949 exit(1);
993 } 950 }
994 951
995 logit(LOG_DEBUG, "<%s> prefix %s/%d was re-enabled on %s", 952 logit(LOG_DEBUG, "<%s> prefix %s/%d was re-enabled on %s",
996 __func__, inet_ntop(AF_INET6, &prefix->prefix, ntopbuf, 953 __func__, inet_ntop(AF_INET6, &prefix->prefix, ntopbuf,
997 INET6_ADDRSTRLEN), prefix->prefixlen, rai->ifname); 954 INET6_ADDRSTRLEN), prefix->prefixlen, rai->ifname);
998 955
999 /* stop the expiration timer */ 956 /* stop the expiration timer */
1000 rtadvd_remove_timer(&prefix->timer); 957 rtadvd_remove_timer(&prefix->timer);
1001} 958}
1002 959
1003/* 960/*
1004 * Try to get an in6_prefixreq contents for a prefix which matches 961 * Add a prefix to the list of specified interface and reconstruct
1005 * ipr->ipr_prefix and ipr->ipr_plen and belongs to 962 * the outgoing packet.
1006 * the interface whose name is ipr->ipr_name[]. 963 * The prefix must not be in the list.
 964 * XXX: other parameters of the prefix(e.g. lifetime) should be
 965 * able to be specified.
1007 */ 966 */
1008static int 967void
1009init_prefix(struct in6_prefixreq *ipr) 968add_prefix(struct rainfo *rai, int ifindex, struct in6_addr *addr, int plen)
1010{ 969{
1011#if 0 970 struct prefix *prefix;
1012 int s; 971 char ntopbuf[INET6_ADDRSTRLEN];
1013 972
1014 if ((s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { 973 if ((prefix = calloc(1, sizeof(*prefix))) == NULL) {
1015 logit(LOG_ERR, "<%s> socket: %m", __func__); 974 logit(LOG_ERR, "<%s> memory allocation failed",
1016 exit(1); 975 __func__);
 976 return; /* XXX: error or exit? */
1017 } 977 }
 978 prefix->prefix = *addr;
 979 prefix->prefixlen = plen;
 980 prefix->validlifetime = DEF_ADVVALIDLIFETIME;
 981 prefix->preflifetime = DEF_ADVPREFERREDLIFETIME;
 982 prefix->onlinkflg = 1;
 983 prefix->autoconfflg = 0;
 984 prefix->origin = PREFIX_FROM_DYNAMIC;
1018 985
1019 if (prog_ioctl(s, SIOCGIFPREFIX_IN6, ipr) < 0) { 986 prefix->rainfo = rai;
1020 logit(LOG_INFO, "<%s> ioctl:SIOCGIFPREFIX: %m", __func__); 987 TAILQ_INSERT_TAIL(&rai->prefix, prefix, next);
 988 rai->pfxs++;
1021 989
1022 ipr->ipr_vltime = DEF_ADVVALIDLIFETIME; 990 logit(LOG_DEBUG, "<%s> new prefix %s/%d was added on %s",
1023 ipr->ipr_pltime = DEF_ADVPREFERREDLIFETIME; 991 __func__, inet_ntop(AF_INET6, addr, ntopbuf, INET6_ADDRSTRLEN),
1024 ipr->ipr_raf_onlink = 1; 992 plen, rai->ifname);
1025 ipr->ipr_raf_auto = 1; 
1026 /* omit other field initialization */ 
1027 } 
1028 else if (ipr->ipr_origin < PR_ORIG_RR) { 
1029 char ntopbuf[INET6_ADDRSTRLEN]; 
1030 
1031 logit(LOG_WARNING, "<%s> Added prefix(%s)'s origin %d is" 
1032 "lower than PR_ORIG_RR(router renumbering)." 
1033 "This should not happen if I am router", __func__, 
1034 inet_ntop(AF_INET6, &ipr->ipr_prefix.sin6_addr, ntopbuf, 
1035 sizeof(ntopbuf)), ipr->ipr_origin); 
1036 prog_close(s); 
1037 return 1; 
1038 } 
1039 
1040 prog_close(s); 
1041 return 0; 
1042#else 
1043 ipr->ipr_vltime = DEF_ADVVALIDLIFETIME; 
1044 ipr->ipr_pltime = DEF_ADVPREFERREDLIFETIME; 
1045 ipr->ipr_raf_onlink = 1; 
1046 ipr->ipr_raf_auto = 1; 
1047 return 0; 
1048#endif 
1049} 
1050 993
1051void 994 /* free the previous packet */
1052make_prefix(struct rainfo *rai, int ifindex, struct in6_addr *addr, int plen) 995 free(rai->ra_data);
1053{ 996 rai->ra_data = NULL;
1054 struct in6_prefixreq ipr; 
1055 997
1056 memset(&ipr, 0, sizeof(ipr)); 998 /* reconstruct the packet */
1057 if (if_indextoname(ifindex, ipr.ipr_name) == NULL) { 999 make_packet(rai);
1058 logit(LOG_ERR, "<%s> Prefix added interface No.%d doesn't" 
1059 "exist. This should not happen: %m", __func__, 
1060 ifindex); 
1061 exit(1); 
1062 } 
1063 ipr.ipr_prefix.sin6_len = sizeof(ipr.ipr_prefix); 
1064 ipr.ipr_prefix.sin6_family = AF_INET6; 
1065 ipr.ipr_prefix.sin6_addr = *addr; 
1066 ipr.ipr_plen = plen; 
1067 
1068 if (init_prefix(&ipr)) 
1069 return; /* init failed by some error */ 
1070 add_prefix(rai, &ipr); 
1071} 1000}
1072 1001
1073void 1002void
1074make_packet(struct rainfo *rainfo) 1003make_packet(struct rainfo *rainfo)
1075{ 1004{
1076 size_t packlen, lladdroptlen = 0; 1005 size_t packlen, lladdroptlen = 0;
1077 char *buf; 1006 char *buf;
1078 struct nd_router_advert *ra; 1007 struct nd_router_advert *ra;
1079 struct nd_opt_prefix_info *ndopt_pi; 1008 struct nd_opt_prefix_info *ndopt_pi;
1080 struct nd_opt_mtu *ndopt_mtu; 1009 struct nd_opt_mtu *ndopt_mtu;
1081 struct prefix *pfx; 1010 struct prefix *pfx;
1082 struct nd_opt_route_info *ndopt_rti; 1011 struct nd_opt_route_info *ndopt_rti;
1083 struct rtinfo *rti; 1012 struct rtinfo *rti;

cvs diff -r1.10 -r1.11 src/usr.sbin/rtadvd/config.h (expand / switch to unified 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,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: config.h,v 1.10 2018/04/20 10:39:37 roy Exp $ */ 1/* $NetBSD: config.h,v 1.11 2020/04/21 12:16:47 roy Exp $ */
2/* $KAME: config.h,v 1.9 2003/08/06 04:19:40 ono Exp $ */ 2/* $KAME: config.h,v 1.9 2003/08/06 04:19:40 ono Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -25,25 +25,25 @@ @@ -25,25 +25,25 @@
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE. 30 * SUCH DAMAGE.
31 */ 31 */
32 32
33extern void free_rainfo(struct rainfo *); 33extern void free_rainfo(struct rainfo *);
34extern void getconfig(const char *, int); 34extern void getconfig(const char *, int);
35extern void delete_prefix(struct prefix *); 35extern void delete_prefix(struct prefix *);
36extern void invalidate_prefix(struct prefix *); 36extern void invalidate_prefix(struct prefix *);
37extern void update_prefix(struct prefix *); 37extern void update_prefix(struct prefix *);
38extern void make_prefix(struct rainfo *, int, struct in6_addr *, int); 38extern void add_prefix(struct rainfo *, int, struct in6_addr *, int);
39extern void make_packet(struct rainfo *); 39extern void make_packet(struct rainfo *);
40extern void get_prefix(struct rainfo *); 40extern void get_prefix(struct rainfo *);
41 41
42/* 42/*
43 * it is highly unlikely to have 100 information options, 43 * it is highly unlikely to have 100 information options,
44 * so it should be okay to limit it 44 * so it should be okay to limit it
45 */ 45 */
46#define MAXPREFIX 100 46#define MAXPREFIX 100
47#define MAXROUTE 100 47#define MAXROUTE 100
48#define MAXRDNSS 100 48#define MAXRDNSS 100
49#define MAXDNSSL 100 49#define MAXDNSSL 100

cvs diff -r1.72 -r1.73 src/usr.sbin/rtadvd/rtadvd.c (expand / switch to unified 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,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rtadvd.c,v 1.72 2020/04/21 12:05:54 roy Exp $ */ 1/* $NetBSD: rtadvd.c,v 1.73 2020/04/21 12:16:47 roy Exp $ */
2/* $KAME: rtadvd.c,v 1.92 2005/10/17 14:40:02 suz Exp $ */ 2/* $KAME: rtadvd.c,v 1.92 2005/10/17 14:40:02 suz Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -605,27 +605,27 @@ rtmsg_input(void) @@ -605,27 +605,27 @@ rtmsg_input(void)
605 prefixchange = 1; 605 prefixchange = 1;
606 } else if (dflag > 1) { 606 } else if (dflag > 1) {
607 logit(LOG_DEBUG, 607 logit(LOG_DEBUG,
608 "%s: new prefix(%s/%d) " 608 "%s: new prefix(%s/%d) "
609 "added on %s, " 609 "added on %s, "
610 "but it was already in list", 610 "but it was already in list",
611 __func__, 611 __func__,
612 inet_ntop(AF_INET6, addr, 612 inet_ntop(AF_INET6, addr,
613 (char *)addrbuf, INET6_ADDRSTRLEN), 613 (char *)addrbuf, INET6_ADDRSTRLEN),
614 plen, rai->ifname); 614 plen, rai->ifname);
615 } 615 }
616 break; 616 break;
617 } 617 }
618 make_prefix(rai, ifindex, addr, plen); 618 add_prefix(rai, ifindex, addr, plen);
619 prefixchange = 1; 619 prefixchange = 1;
620 break; 620 break;
621 case RTM_DELETE: 621 case RTM_DELETE:
622 /* init ifflags because it may have changed */ 622 /* init ifflags because it may have changed */
623 rai->ifflags = if_getflags(ifindex, rai->ifflags); 623 rai->ifflags = if_getflags(ifindex, rai->ifflags);
624 624
625 if (sflag) 625 if (sflag)
626 break; 626 break;
627 627
628 addr = get_addr(msg); 628 addr = get_addr(msg);
629 plen = get_prefixlen(msg); 629 plen = get_prefixlen(msg);
630 /* sanity check for plen */ 630 /* sanity check for plen */
631 /* as RFC2373, prefixlen is at least 4 */ 631 /* as RFC2373, prefixlen is at least 4 */