Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Nov 2015 01:54:00 +0300
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        "Alexander V. Chernikov" <melifaro@FreeBSD.org>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r290603 - in head/sys: net netgraph netinet
Message-ID:  <20151113225400.GE73031@FreeBSD.org>
In-Reply-To: <201511091011.tA9ABFWb029549@repo.freebsd.org>
References:  <201511091011.tA9ABFWb029549@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
  Alexander,

On Mon, Nov 09, 2015 at 10:11:15AM +0000, Alexander V. Chernikov wrote:
A> Author: melifaro
A> Date: Mon Nov  9 10:11:14 2015
A> New Revision: 290603
A> URL: https://svnweb.freebsd.org/changeset/base/290603
A> 
A> Log:
A>   Use lladdr_event to propagate gratiotus arp.
A>   
A>   Differential Revision:	https://reviews.freebsd.org/D4019

Looking into a diff a lame question emerges: why can't the call
to EVENTHANDLER_INVOKE() moved right into the end of the
if_setlladdr()?

A> Modified:
A>   head/sys/net/if.c
A>   head/sys/net/if_vlan.c
A>   head/sys/netgraph/ng_eiface.c
A>   head/sys/netgraph/ng_ether.c
A>   head/sys/netinet/if_ether.c
A> 
A> Modified: head/sys/net/if.c
A> ==============================================================================
A> --- head/sys/net/if.c	Mon Nov  9 09:39:59 2015	(r290602)
A> +++ head/sys/net/if.c	Mon Nov  9 10:11:14 2015	(r290603)
A> @@ -2512,7 +2512,8 @@ ifhwioctl(u_long cmd, struct ifnet *ifp,
A>  			return (error);
A>  		error = if_setlladdr(ifp,
A>  		    ifr->ifr_addr.sa_data, ifr->ifr_addr.sa_len);
A> -		EVENTHANDLER_INVOKE(iflladdr_event, ifp);
A> +		if (error == 0)
A> +			EVENTHANDLER_INVOKE(iflladdr_event, ifp);
A>  		break;
A>  
A>  	case SIOCAIFGROUP:
A> @@ -3375,16 +3376,6 @@ if_setlladdr(struct ifnet *ifp, const u_
A>  			ifr.ifr_flagshigh = ifp->if_flags >> 16;
A>  			(*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr);
A>  		}
A> -#ifdef INET
A> -		/*
A> -		 * Also send gratuitous ARPs to notify other nodes about
A> -		 * the address change.
A> -		 */
A> -		TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
A> -			if (ifa->ifa_addr->sa_family == AF_INET)
A> -				arp_ifinit(ifp, ifa);
A> -		}
A> -#endif
A>  	}
A>  	return (0);
A>  }
A> 
A> Modified: head/sys/net/if_vlan.c
A> ==============================================================================
A> --- head/sys/net/if_vlan.c	Mon Nov  9 09:39:59 2015	(r290602)
A> +++ head/sys/net/if_vlan.c	Mon Nov  9 10:11:14 2015	(r290603)
A> @@ -523,7 +523,7 @@ vlan_iflladdr(void *arg __unused, struct
A>  #ifndef VLAN_ARRAY
A>  	struct ifvlan *next;
A>  #endif
A> -	int i;
A> +	int error, i;
A>  
A>  	/*
A>  	 * Check if it's a trunk interface first of all
A> @@ -544,8 +544,11 @@ vlan_iflladdr(void *arg __unused, struct
A>  		LIST_FOREACH_SAFE(ifv, &ifp->if_vlantrunk->hash[i], ifv_list, next) {
A>  #endif /* VLAN_ARRAY */
A>  			VLAN_UNLOCK();
A> -			if_setlladdr(ifv->ifv_ifp, IF_LLADDR(ifp),
A> +			error = if_setlladdr(ifv->ifv_ifp, IF_LLADDR(ifp),
A>  			    ifp->if_addrlen);
A> +			if (error == 0)
A> +				EVENTHANDLER_INVOKE(iflladdr_event,
A> +				    ifv->ifv_ifp);
A>  			VLAN_LOCK();
A>  		}
A>  	VLAN_UNLOCK();
A> 
A> Modified: head/sys/netgraph/ng_eiface.c
A> ==============================================================================
A> --- head/sys/netgraph/ng_eiface.c	Mon Nov  9 09:39:59 2015	(r290602)
A> +++ head/sys/netgraph/ng_eiface.c	Mon Nov  9 10:11:14 2015	(r290603)
A> @@ -489,7 +489,8 @@ ng_eiface_rcvmsg(node_p node, item_p ite
A>  			}
A>  			error = if_setlladdr(priv->ifp,
A>  			    (u_char *)msg->data, ETHER_ADDR_LEN);
A> -			EVENTHANDLER_INVOKE(iflladdr_event, priv->ifp);
A> +			if (error == 0)
A> +				EVENTHANDLER_INVOKE(iflladdr_event, priv->ifp);
A>  			break;
A>  		    }
A>  
A> 
A> Modified: head/sys/netgraph/ng_ether.c
A> ==============================================================================
A> --- head/sys/netgraph/ng_ether.c	Mon Nov  9 09:39:59 2015	(r290602)
A> +++ head/sys/netgraph/ng_ether.c	Mon Nov  9 10:11:14 2015	(r290603)
A> @@ -534,7 +534,8 @@ ng_ether_rcvmsg(node_p node, item_p item
A>  			}
A>  			error = if_setlladdr(priv->ifp,
A>  			    (u_char *)msg->data, ETHER_ADDR_LEN);
A> -			EVENTHANDLER_INVOKE(iflladdr_event, priv->ifp);
A> +			if (error == 0)
A> +				EVENTHANDLER_INVOKE(iflladdr_event, priv->ifp);
A>  			break;
A>  		    }
A>  		case NGM_ETHER_GET_PROMISC:
A> 
A> Modified: head/sys/netinet/if_ether.c
A> ==============================================================================
A> --- head/sys/netinet/if_ether.c	Mon Nov  9 09:39:59 2015	(r290602)
A> +++ head/sys/netinet/if_ether.c	Mon Nov  9 10:11:14 2015	(r290603)
A> @@ -142,7 +142,9 @@ static void	in_arpinput(struct mbuf *);
A>  static void arp_check_update_lle(struct arphdr *ah, struct in_addr isaddr,
A>      struct ifnet *ifp, int bridged, struct llentry *la);
A>  static void arp_mark_lle_reachable(struct llentry *la);
A> +static void arp_iflladdr(void *arg __unused, struct ifnet *ifp);
A>  
A> +static eventhandler_tag iflladdr_tag;
A>  
A>  static const struct netisr_handler arp_nh = {
A>  	.nh_name = "arp",
A> @@ -1150,10 +1152,39 @@ arp_ifinit2(struct ifnet *ifp, struct if
A>  	ifa->ifa_rtrequest = NULL;
A>  }
A>  
A> +/*
A> + * Sends gratuitous ARPs for each ifaddr to notify other
A> + * nodes about the address change.
A> + */
A> +static __noinline void
A> +arp_handle_ifllchange(struct ifnet *ifp)
A> +{
A> +	struct ifaddr *ifa;
A> +
A> +	TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
A> +		if (ifa->ifa_addr->sa_family == AF_INET)
A> +			arp_ifinit(ifp, ifa);
A> +	}
A> +}
A> +
A> +/*
A> + * A handler for interface link layer address change event.
A> + */
A> +static __noinline void
A> +arp_iflladdr(void *arg __unused, struct ifnet *ifp)
A> +{
A> +
A> +	if ((ifp->if_flags & IFF_UP) != 0)
A> +		arp_handle_ifllchange(ifp);
A> +}
A> +
A>  static void
A>  arp_init(void)
A>  {
A>  
A>  	netisr_register(&arp_nh);
A> +	if (IS_DEFAULT_VNET(curvnet))
A> +		iflladdr_tag = EVENTHANDLER_REGISTER(iflladdr_event,
A> +		    arp_iflladdr, NULL, EVENTHANDLER_PRI_ANY);
A>  }
A>  SYSINIT(arp, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, arp_init, 0);
A> 

-- 
Totus tuus, Glebius.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20151113225400.GE73031>