Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Sep 2014 12:54:25 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r272178 - head/sys/net
Message-ID:  <201409261254.s8QCsPe4054147@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glebius
Date: Fri Sep 26 12:54:24 2014
New Revision: 272178
URL: http://svnweb.freebsd.org/changeset/base/272178

Log:
  Make all lagg protocol methods live in lagg_protos, not in softc. All
  interfaces of a same protocol, use the same methods.
  
  Sponsored by:	Netflix
  Sponsored by:	Nginx, Inc.

Modified:
  head/sys/net/if_lagg.c
  head/sys/net/if_lagg.h

Modified: head/sys/net/if_lagg.c
==============================================================================
--- head/sys/net/if_lagg.c	Fri Sep 26 12:48:54 2014	(r272177)
+++ head/sys/net/if_lagg.c	Fri Sep 26 12:54:24 2014	(r272178)
@@ -131,7 +131,6 @@ static struct mbuf *lagg_rr_input(struct
 		    struct mbuf *);
 
 /* Active failover */
-static void	lagg_fail_attach(struct lagg_softc *);
 static int	lagg_fail_start(struct lagg_softc *, struct mbuf *);
 static struct mbuf *lagg_fail_input(struct lagg_softc *, struct lagg_port *,
 		    struct mbuf *);
@@ -147,7 +146,6 @@ static struct mbuf *lagg_lb_input(struct
 static int	lagg_lb_porttable(struct lagg_softc *, struct lagg_port *);
 
 /* Broadcast */
-static void	lagg_bcast_attach(struct lagg_softc *);
 static int    lagg_bcast_start(struct lagg_softc *, struct mbuf *);
 static struct mbuf *lagg_bcast_input(struct lagg_softc *, struct lagg_port *,
 		    struct mbuf *);
@@ -167,6 +165,17 @@ static const struct lagg_proto {
 	lagg_proto	pr_num;
 	void		(*pr_attach)(struct lagg_softc *);
 	void		(*pr_detach)(struct lagg_softc *);
+	int		(*pr_start)(struct lagg_softc *, struct mbuf *);
+	struct mbuf *	(*pr_input)(struct lagg_softc *, struct lagg_port *,
+			    struct mbuf *);
+	int		(*pr_addport)(struct lagg_port *);
+	void		(*pr_delport)(struct lagg_port *);
+	void		(*pr_linkstate)(struct lagg_port *);
+	void 		(*pr_init)(struct lagg_softc *);
+	void 		(*pr_stop)(struct lagg_softc *);
+	void 		(*pr_lladdr)(struct lagg_softc *);
+	void		(*pr_request)(struct lagg_softc *, void *);
+	void		(*pr_portreq)(struct lagg_port *, void *);
 } lagg_protos[] = {
     {
 	.pr_num = LAGG_PROTO_NONE
@@ -174,28 +183,49 @@ static const struct lagg_proto {
     {
 	.pr_num = LAGG_PROTO_ROUNDROBIN,
 	.pr_attach = lagg_rr_attach,
+	.pr_start = lagg_rr_start,
+	.pr_input = lagg_rr_input,
     },
     {
 	.pr_num = LAGG_PROTO_FAILOVER,
-	.pr_attach = lagg_fail_attach,
+	.pr_start = lagg_fail_start,
+	.pr_input = lagg_fail_input,
     },
     {
 	.pr_num = LAGG_PROTO_LOADBALANCE,
 	.pr_attach = lagg_lb_attach,
 	.pr_detach = lagg_lb_detach,
+	.pr_start = lagg_lb_start,
+	.pr_input = lagg_lb_input,
+	.pr_addport = lagg_lb_port_create,
+	.pr_delport = lagg_lb_port_destroy,
     },
     {
 	.pr_num = LAGG_PROTO_LACP,
 	.pr_attach = lagg_lacp_attach,
 	.pr_detach = lagg_lacp_detach,
+	.pr_start = lagg_lacp_start,
+	.pr_input = lagg_lacp_input,
+	.pr_addport = lacp_port_create,
+	.pr_delport = lacp_port_destroy,
+	.pr_linkstate = lacp_linkstate,
+	.pr_init = lacp_init,
+	.pr_stop = lacp_stop,
+	.pr_lladdr = lagg_lacp_lladdr,
+	.pr_request = lacp_req,
+	.pr_portreq = lacp_portreq,
     },
     {
 	.pr_num = LAGG_PROTO_ETHERCHANNEL,
 	.pr_attach = lagg_lb_attach,
+	.pr_detach = lagg_lb_detach,
+	.pr_start = lagg_lb_start,
+	.pr_input = lagg_lb_input,
     },
     {
 	.pr_num = LAGG_PROTO_BROADCAST,
-	.pr_attach = lagg_bcast_attach,
+	.pr_start = lagg_bcast_start,
+	.pr_input = lagg_bcast_input,
     },
 };
 
@@ -265,7 +295,8 @@ lagg_proto_attach(struct lagg_softc *sc,
 	if (sc->sc_ifflags & IFF_DEBUG)
 		if_printf(sc->sc_ifp, "using proto %u\n", pr);
 
-	lagg_protos[pr].pr_attach(sc);
+	if (lagg_protos[pr].pr_attach != NULL)
+		lagg_protos[pr].pr_attach(sc);
 	sc->sc_proto = pr;
 }
 
@@ -285,6 +316,86 @@ lagg_proto_detach(struct lagg_softc *sc)
 		LAGG_WUNLOCK(sc);
 }
 
+static int
+lagg_proto_start(struct lagg_softc *sc, struct mbuf *m)
+{
+
+	return (lagg_protos[sc->sc_proto].pr_start(sc, m));
+}
+
+static struct mbuf *
+lagg_proto_input(struct lagg_softc *sc, struct lagg_port *lp, struct mbuf *m)
+{
+
+	return (lagg_protos[sc->sc_proto].pr_input(sc, lp, m));
+}
+
+static int
+lagg_proto_addport(struct lagg_softc *sc, struct lagg_port *lp)
+{
+
+	if (lagg_protos[sc->sc_proto].pr_addport == NULL)
+		return (0);
+	else
+		return (lagg_protos[sc->sc_proto].pr_addport(lp));
+}
+
+static void
+lagg_proto_delport(struct lagg_softc *sc, struct lagg_port *lp)
+{
+
+	if (lagg_protos[sc->sc_proto].pr_delport != NULL)
+		lagg_protos[sc->sc_proto].pr_delport(lp);
+}
+
+static void
+lagg_proto_linkstate(struct lagg_softc *sc, struct lagg_port *lp)
+{
+
+	if (lagg_protos[sc->sc_proto].pr_linkstate != NULL)
+		lagg_protos[sc->sc_proto].pr_linkstate(lp);
+}
+
+static void
+lagg_proto_init(struct lagg_softc *sc)
+{
+
+	if (lagg_protos[sc->sc_proto].pr_init != NULL)
+		lagg_protos[sc->sc_proto].pr_init(sc);
+}
+
+static void
+lagg_proto_stop(struct lagg_softc *sc)
+{
+
+	if (lagg_protos[sc->sc_proto].pr_stop != NULL)
+		lagg_protos[sc->sc_proto].pr_stop(sc);
+}
+
+static void
+lagg_proto_lladdr(struct lagg_softc *sc)
+{
+
+	if (lagg_protos[sc->sc_proto].pr_lladdr != NULL)
+		lagg_protos[sc->sc_proto].pr_lladdr(sc);
+}
+
+static void
+lagg_proto_request(struct lagg_softc *sc, void *v)
+{
+
+	if (lagg_protos[sc->sc_proto].pr_request != NULL)
+		lagg_protos[sc->sc_proto].pr_request(sc, v);
+}
+
+static void
+lagg_proto_portreq(struct lagg_softc *sc, struct lagg_port *lp, void *v)
+{
+
+	if (lagg_protos[sc->sc_proto].pr_portreq != NULL)
+		lagg_protos[sc->sc_proto].pr_portreq(lp, v);
+}
+
 /*
  * This routine is run via an vlan
  * config EVENT
@@ -479,8 +590,7 @@ lagg_lladdr(struct lagg_softc *sc, uint8
 
 	bcopy(lladdr, IF_LLADDR(ifp), ETHER_ADDR_LEN);
 	/* Let the protocol know the MAC has changed */
-	if (sc->sc_lladdr != NULL)
-		(*sc->sc_lladdr)(sc);
+	lagg_proto_lladdr(sc);
 	EVENTHANDLER_INVOKE(iflladdr_event, ifp);
 }
 
@@ -602,7 +712,7 @@ lagg_port_create(struct lagg_softc *sc, 
 {
 	struct lagg_softc *sc_ptr;
 	struct lagg_port *lp, *tlp;
-	int error = 0;
+	int error;
 
 	LAGG_WLOCK_ASSERT(sc);
 
@@ -730,15 +840,13 @@ lagg_port_create(struct lagg_softc *sc, 
 	lagg_ether_cmdmulti(lp, 1);
 	lagg_setflags(lp, 1);
 
-	if (sc->sc_port_create != NULL)
-		error = (*sc->sc_port_create)(lp);
-	if (error) {
-		/* remove the port again, without calling sc_port_destroy */
+	if ((error = lagg_proto_addport(sc, lp)) != 0) {
+		/* Remove the port, without calling pr_delport. */
 		lagg_port_destroy(lp, 0);
 		return (error);
 	}
 
-	return (error);
+	return (0);
 }
 
 #ifdef LAGG_PORT_STACKING
@@ -763,7 +871,7 @@ lagg_port_checkstacking(struct lagg_soft
 #endif
 
 static int
-lagg_port_destroy(struct lagg_port *lp, int runpd)
+lagg_port_destroy(struct lagg_port *lp, int rundelport)
 {
 	struct lagg_softc *sc = lp->lp_softc;
 	struct lagg_port *lp_ptr;
@@ -772,8 +880,8 @@ lagg_port_destroy(struct lagg_port *lp, 
 
 	LAGG_WLOCK_ASSERT(sc);
 
-	if (runpd && sc->sc_port_destroy != NULL)
-		(*sc->sc_port_destroy)(lp);
+	if (rundelport)
+		lagg_proto_delport(sc, lp);
 
 	/*
 	 * Remove multicast addresses and interface flags from this port and
@@ -952,8 +1060,7 @@ lagg_port2req(struct lagg_port *lp, stru
 	strlcpy(rp->rp_portname, lp->lp_ifp->if_xname, sizeof(rp->rp_portname));
 	rp->rp_prio = lp->lp_prio;
 	rp->rp_flags = lp->lp_flags;
-	if (sc->sc_portreq != NULL)
-		(*sc->sc_portreq)(lp, &rp->rp_psc);
+	lagg_proto_portreq(sc, lp, &rp->rp_psc);
 
 	/* Add protocol specific flags */
 	switch (sc->sc_proto) {
@@ -1002,8 +1109,7 @@ lagg_init(void *xsc)
 	SLIST_FOREACH(lp, &sc->sc_ports, lp_entries)
 		lagg_port_lladdr(lp, IF_LLADDR(ifp));
 
-	if (sc->sc_init != NULL)
-		(*sc->sc_init)(sc);
+	lagg_proto_init(sc);
 
 	LAGG_WUNLOCK(sc);
 }
@@ -1020,8 +1126,7 @@ lagg_stop(struct lagg_softc *sc)
 
 	ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
 
-	if (sc->sc_stop != NULL)
-		(*sc->sc_stop)(sc);
+	lagg_proto_stop(sc);
 }
 
 static int
@@ -1054,9 +1159,7 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd
 
 		LAGG_RLOCK(sc, &tracker);
 		ra->ra_proto = sc->sc_proto;
-		if (sc->sc_req != NULL)
-			(*sc->sc_req)(sc, &ra->ra_psc);
-
+		lagg_proto_request(sc, &ra->ra_psc);
 		count = 0;
 		buf = outbuf;
 		len = min(ra->ra_size, buflen);
@@ -1343,7 +1446,7 @@ lagg_transmit(struct ifnet *ifp, struct 
 
 	ETHER_BPF_MTAP(ifp, m);
 
-	error = (*sc->sc_start)(sc, m);
+	error = lagg_proto_start(sc, m);
 	LAGG_RUNLOCK(sc, &tracker);
 
 	if (error == 0) {
@@ -1383,7 +1486,7 @@ lagg_input(struct ifnet *ifp, struct mbu
 
 	ETHER_BPF_MTAP(scifp, m);
 
-	m = (*sc->sc_input)(sc, lp, m);
+	m = lagg_proto_input(sc, lp, m);
 
 	if (m != NULL) {
 		counter_u64_add(sc->sc_ipackets, 1);
@@ -1479,8 +1582,7 @@ lagg_port_state(struct ifnet *ifp, int s
 
 	LAGG_WLOCK(sc);
 	lagg_linkstate(sc);
-	if (sc->sc_linkstate != NULL)
-		(*sc->sc_linkstate)(lp);
+	lagg_proto_linkstate(sc, lp);
 	LAGG_WUNLOCK(sc);
 }
 
@@ -1683,9 +1785,6 @@ lagg_enqueue(struct ifnet *ifp, struct m
 static void
 lagg_rr_attach(struct lagg_softc *sc)
 {
-	sc->sc_start = lagg_rr_start;
-	sc->sc_input = lagg_rr_input;
-	sc->sc_port_create = NULL;
 	sc->sc_capabilities = IFCAP_LAGG_FULLDUPLEX;
 	sc->sc_seq = 0;
 }
@@ -1729,18 +1828,6 @@ lagg_rr_input(struct lagg_softc *sc, str
 /*
  * Broadcast mode
  */
-static void
-lagg_bcast_attach(struct lagg_softc *sc)
-{
-	sc->sc_start = lagg_bcast_start;
-	sc->sc_input = lagg_bcast_input;
-	sc->sc_port_create = NULL;
-	sc->sc_port_destroy = NULL;
-	sc->sc_linkstate = NULL;
-	sc->sc_req = NULL;
-	sc->sc_portreq = NULL;
-}
-
 static int
 lagg_bcast_start(struct lagg_softc *sc, struct mbuf *m)
 {
@@ -1802,15 +1889,6 @@ lagg_bcast_input(struct lagg_softc *sc, 
 /*
  * Active failover
  */
-static void
-lagg_fail_attach(struct lagg_softc *sc)
-{
-	sc->sc_start = lagg_fail_start;
-	sc->sc_input = lagg_fail_input;
-	sc->sc_port_create = NULL;
-	sc->sc_port_destroy = NULL;
-}
-
 static int
 lagg_fail_start(struct lagg_softc *sc, struct mbuf *m)
 {
@@ -1864,10 +1942,6 @@ lagg_lb_attach(struct lagg_softc *sc)
 
 	lb = malloc(sizeof(struct lagg_lb), M_DEVBUF, M_WAITOK | M_ZERO);
 
-	sc->sc_start = lagg_lb_start;
-	sc->sc_input = lagg_lb_input;
-	sc->sc_port_create = lagg_lb_port_create;
-	sc->sc_port_destroy = lagg_lb_port_destroy;
 	sc->sc_capabilities = IFCAP_LAGG_FULLDUPLEX;
 
 	lb->lb_key = arc4random();
@@ -1970,19 +2044,7 @@ lagg_lacp_attach(struct lagg_softc *sc)
 {
 	struct lagg_port *lp;
 
-	sc->sc_port_create = lacp_port_create;
-	sc->sc_port_destroy = lacp_port_destroy;
-	sc->sc_linkstate = lacp_linkstate;
-	sc->sc_start = lagg_lacp_start;
-	sc->sc_input = lagg_lacp_input;
-	sc->sc_init = lacp_init;
-	sc->sc_stop = lacp_stop;
-	sc->sc_lladdr = lagg_lacp_lladdr;
-	sc->sc_req = lacp_req;
-	sc->sc_portreq = lacp_portreq;
-
 	lacp_attach(sc);
-
 	SLIST_FOREACH(lp, &sc->sc_ports, lp_entries)
 		lacp_port_create(lp);
 }

Modified: head/sys/net/if_lagg.h
==============================================================================
--- head/sys/net/if_lagg.h	Fri Sep 26 12:48:54 2014	(r272177)
+++ head/sys/net/if_lagg.h	Fri Sep 26 12:54:24 2014	(r272178)
@@ -216,19 +216,6 @@ struct lagg_softc {
 	struct task			sc_lladdr_task;
 	SLIST_HEAD(__llqhd, lagg_llq)	sc_llq_head;	/* interfaces to program
 							   the lladdr on */
-
-	/* lagg protocol callbacks */
-	int	(*sc_start)(struct lagg_softc *, struct mbuf *);
-	struct mbuf *(*sc_input)(struct lagg_softc *, struct lagg_port *,
-		    struct mbuf *);
-	int	(*sc_port_create)(struct lagg_port *);
-	void	(*sc_port_destroy)(struct lagg_port *);
-	void	(*sc_linkstate)(struct lagg_port *);
-	void	(*sc_init)(struct lagg_softc *);
-	void	(*sc_stop)(struct lagg_softc *);
-	void	(*sc_lladdr)(struct lagg_softc *);
-	void	(*sc_req)(struct lagg_softc *, void *);
-	void	(*sc_portreq)(struct lagg_port *, void *);
 	eventhandler_tag vlan_attach;
 	eventhandler_tag vlan_detach;
 	struct callout			sc_callout;



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