Module Name: src Committed By: martin Date: Sat Sep 21 12:26:49 UTC 2024
Modified Files: src/sbin/ifconfig [netbsd-10]: carp.c ifconfig.8 src/sys/netinet [netbsd-10]: ip_carp.c src/tests/net/carp [netbsd-10]: t_basic.sh Log Message: Pull up following revision(s) (requested by rin in ticket #902): sbin/ifconfig/carp.c: revision 1.15 sbin/ifconfig/ifconfig.8: revision 1.125 tests/net/carp/t_basic.sh: revision 1.9 sys/netinet/ip_carp.c: revision 1.118 sys/netinet/ip_carp.c: revision 1.119 Fix parser for carp state. The state values are uppercase words INIT, BACKUP and MASTER. Use backing device to send advertisements. Otherwise the packets originate from the virtual MAC address, which confuses switches. Select virtual address as sender if backing interface is anonymous. Use correct scope for IPv6. Don't expect the net/carp/t_basic/carp_handover_ipv6_halt_nocarpdevip and carp_handover_ipv6_ifdown_nocarpdevip test cases to fail. At least on the TNF i386 and amd64 testbeds, they pass more often than not since the commit of src/sys/netinet/ip_carp.c 1.119 by mlelstv on 2023.04.07.06.44.08. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.14.6.1 src/sbin/ifconfig/carp.c cvs rdiff -u -r1.124.2.2 -r1.124.2.3 src/sbin/ifconfig/ifconfig.8 cvs rdiff -u -r1.117 -r1.117.4.1 src/sys/netinet/ip_carp.c cvs rdiff -u -r1.8 -r1.8.8.1 src/tests/net/carp/t_basic.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/ifconfig/carp.c diff -u src/sbin/ifconfig/carp.c:1.14 src/sbin/ifconfig/carp.c:1.14.6.1 --- src/sbin/ifconfig/carp.c:1.14 Sun Jun 7 06:02:58 2020 +++ src/sbin/ifconfig/carp.c Sat Sep 21 12:26:48 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: carp.c,v 1.14 2020/06/07 06:02:58 thorpej Exp $ */ +/* $NetBSD: carp.c,v 1.14.6.1 2024/09/21 12:26:48 martin Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff. All rights reserved. @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: carp.c,v 1.14 2020/06/07 06:02:58 thorpej Exp $"); +__RCSID("$NetBSD: carp.c,v 1.14.6.1 2024/09/21 12:26:48 martin Exp $"); #endif /* not lint */ #include <sys/param.h> @@ -67,10 +67,16 @@ static int setcarpdev(prop_dictionary_t, static const char *carp_states[] = { CARP_STATES }; +/* from if_carp.c */ +enum carpstateval { INIT = 0, BACKUP, MASTER }; + struct kwinst carpstatekw[] = { - {.k_word = "INIT", .k_nextparser = &command_root.pb_parser} - , {.k_word = "BACKUP", .k_nextparser = &command_root.pb_parser} - , {.k_word = "MASTER", .k_nextparser = &command_root.pb_parser} + {.k_word = "INIT", .k_type = KW_T_INT, .k_int = INIT, + .k_nextparser = &command_root.pb_parser} + , {.k_word = "BACKUP", .k_type = KW_T_INT, .k_int = BACKUP, + .k_nextparser = &command_root.pb_parser} + , {.k_word = "MASTER", .k_type = KW_T_INT, .k_int = MASTER, + .k_nextparser = &command_root.pb_parser} }; struct pinteger parse_advbase = PINTEGER_INITIALIZER1(&parse_advbase, "advbase", Index: src/sbin/ifconfig/ifconfig.8 diff -u src/sbin/ifconfig/ifconfig.8:1.124.2.2 src/sbin/ifconfig/ifconfig.8:1.124.2.3 --- src/sbin/ifconfig/ifconfig.8:1.124.2.2 Sat Aug 24 16:42:26 2024 +++ src/sbin/ifconfig/ifconfig.8 Sat Sep 21 12:26:48 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: ifconfig.8,v 1.124.2.2 2024/08/24 16:42:26 martin Exp $ +.\" $NetBSD: ifconfig.8,v 1.124.2.3 2024/09/21 12:26:48 martin Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -315,10 +315,10 @@ Explicitly force the .Xr carp 4 pseudo-device to enter this state. Valid states are -.Ar init , -.Ar backup , +.Ar INIT , +.Ar BACKUP , and -.Ar master . +.Ar MASTER . .It Cm frag Ar threshold .Pq IEEE 802.11 devices only Configure the fragmentation threshold for IEEE 802.11-based wireless Index: src/sys/netinet/ip_carp.c diff -u src/sys/netinet/ip_carp.c:1.117 src/sys/netinet/ip_carp.c:1.117.4.1 --- src/sys/netinet/ip_carp.c:1.117 Fri Sep 2 23:48:11 2022 +++ src/sys/netinet/ip_carp.c Sat Sep 21 12:26:49 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: ip_carp.c,v 1.117 2022/09/02 23:48:11 thorpej Exp $ */ +/* $NetBSD: ip_carp.c,v 1.117.4.1 2024/09/21 12:26:49 martin Exp $ */ /* $OpenBSD: ip_carp.c,v 1.113 2005/11/04 08:11:54 mcbride Exp $ */ /* @@ -33,7 +33,7 @@ #endif #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.117 2022/09/02 23:48:11 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.117.4.1 2024/09/21 12:26:49 martin Exp $"); /* * TODO: @@ -1091,6 +1091,8 @@ carp_send_ad(void *v) _s = pserialize_read_enter(); ifa = ifaof_ifpforaddr(&sa, sc->sc_carpdev); if (ifa == NULL) + ifa = ifaof_ifpforaddr(&sa, &sc->sc_if); + if (ifa == NULL) ip->ip_src.s_addr = 0; else ip->ip_src.s_addr = @@ -1142,6 +1144,7 @@ carp_send_ad(void *v) if (sc->sc_naddrs6) { struct ip6_hdr *ip6; struct ifaddr *ifa; + struct ifnet *ifp; int _s; MGETHDR(m, M_DONTWAIT, MT_HEADER); @@ -1168,7 +1171,12 @@ carp_send_ad(void *v) memset(&sa, 0, sizeof(sa)); sa.sa_family = AF_INET6; _s = pserialize_read_enter(); - ifa = ifaof_ifpforaddr(&sa, sc->sc_carpdev); + ifp = sc->sc_carpdev; + ifa = ifaof_ifpforaddr(&sa, ifp); + if (ifa == NULL) { /* This should never happen with IPv6 */ + ifp = &sc->sc_if; + ifa = ifaof_ifpforaddr(&sa, ifp); + } if (ifa == NULL) /* This should never happen with IPv6 */ memset(&ip6->ip6_src, 0, sizeof(struct in6_addr)); else @@ -1179,7 +1187,7 @@ carp_send_ad(void *v) ip6->ip6_dst.s6_addr16[0] = htons(0xff02); ip6->ip6_dst.s6_addr8[15] = 0x12; - if (in6_setscope(&ip6->ip6_dst, &sc->sc_if, NULL) != 0) { + if (in6_setscope(&ip6->ip6_dst, ifp, NULL) != 0) { if_statinc(&sc->sc_if, if_oerrors); m_freem(m); CARP_LOG(sc, ("in6_setscope failed")); @@ -1876,6 +1884,9 @@ carp_join_multicast(struct carp_softc *s struct ip_moptions *imo = &sc->sc_imo, tmpimo; struct in_addr addr; + if (sc->sc_carpdev == NULL) + return (ENETDOWN); + memset(&tmpimo, 0, sizeof(tmpimo)); addr.s_addr = INADDR_CARP_GROUP; if ((tmpimo.imo_membership[0] = @@ -1885,7 +1896,7 @@ carp_join_multicast(struct carp_softc *s imo->imo_membership[0] = tmpimo.imo_membership[0]; imo->imo_num_memberships = 1; - imo->imo_multicast_if_index = sc->sc_if.if_index; + imo->imo_multicast_if_index = sc->sc_carpdev->if_index; imo->imo_multicast_ttl = CARP_DFLTTL; imo->imo_multicast_loop = 0; return (0); @@ -1970,6 +1981,9 @@ carp_join_multicast6(struct carp_softc * struct sockaddr_in6 addr6; int error; + if (sc->sc_carpdev == NULL) + return (ENETDOWN); + /* Join IPv6 CARP multicast group */ memset(&addr6, 0, sizeof(addr6)); addr6.sin6_family = AF_INET6; @@ -1996,7 +2010,7 @@ carp_join_multicast6(struct carp_softc * } /* apply v6 multicast membership */ - im6o->im6o_multicast_if_index = sc->sc_if.if_index; + im6o->im6o_multicast_if_index = sc->sc_carpdev->if_index; if (imm) LIST_INSERT_HEAD(&im6o->im6o_memberships, imm, i6mm_chain); Index: src/tests/net/carp/t_basic.sh diff -u src/tests/net/carp/t_basic.sh:1.8 src/tests/net/carp/t_basic.sh:1.8.8.1 --- src/tests/net/carp/t_basic.sh:1.8 Mon Aug 19 03:22:05 2019 +++ src/tests/net/carp/t_basic.sh Sat Sep 21 12:26:48 2024 @@ -1,4 +1,4 @@ -# $NetBSD: t_basic.sh,v 1.8 2019/08/19 03:22:05 ozaki-r Exp $ +# $NetBSD: t_basic.sh,v 1.8.8.1 2024/09/21 12:26:48 martin Exp $ # # Copyright (c) 2017 Internet Initiative Japan Inc. # All rights reserved. @@ -328,9 +328,6 @@ add_test_case() name="${name}_nocarpdevip" desc="$desc without carpdev IP" fi - if [ $ipproto = ipv6 -a $carpdevip = no ]; then - expected_failure_code="atf_expect_fail 'nd6 needs to be fixed';" - fi atf_test_case ${name} cleanup eval "