if_lagg.c (292402) | if_lagg.c (294615) |
---|---|
1/* $OpenBSD: if_trunk.c,v 1.30 2007/01/31 06:20:19 reyk Exp $ */ 2 3/* 4 * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org> 5 * Copyright (c) 2007 Andrew Thompson <thompsa@FreeBSD.org> | 1/* $OpenBSD: if_trunk.c,v 1.30 2007/01/31 06:20:19 reyk Exp $ */ 2 3/* 4 * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org> 5 * Copyright (c) 2007 Andrew Thompson <thompsa@FreeBSD.org> |
6 * Copyright (c) 2014 Marcelo Araujo | 6 * Copyright (c) 2014, 2016 Marcelo Araujo <araujo@FreeBSD.org> |
7 * 8 * Permission to use, copy, modify, and distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above 10 * copyright notice and this permission notice appear in all copies. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 */ 20 21#include <sys/cdefs.h> | 7 * 8 * Permission to use, copy, modify, and distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above 10 * copyright notice and this permission notice appear in all copies. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 */ 20 21#include <sys/cdefs.h> |
22__FBSDID("$FreeBSD: head/sys/net/if_lagg.c 292402 2015-12-17 14:41:30Z smh $"); | 22__FBSDID("$FreeBSD: head/sys/net/if_lagg.c 294615 2016-01-23 04:18:44Z araujo $"); |
23 24#include "opt_inet.h" 25#include "opt_inet6.h" 26 27#include <sys/param.h> 28#include <sys/kernel.h> 29#include <sys/malloc.h> 30#include <sys/mbuf.h> --- 1255 unchanged lines hidden (view full) --- 1286 ro->ro_opts |= LAGG_OPT_LACP_TIMEOUT; 1287 1288 ro->ro_active = sc->sc_active; 1289 } else { 1290 ro->ro_active = 0; 1291 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries) 1292 ro->ro_active += LAGG_PORTACTIVE(lp); 1293 } | 23 24#include "opt_inet.h" 25#include "opt_inet6.h" 26 27#include <sys/param.h> 28#include <sys/kernel.h> 29#include <sys/malloc.h> 30#include <sys/mbuf.h> --- 1255 unchanged lines hidden (view full) --- 1286 ro->ro_opts |= LAGG_OPT_LACP_TIMEOUT; 1287 1288 ro->ro_active = sc->sc_active; 1289 } else { 1290 ro->ro_active = 0; 1291 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries) 1292 ro->ro_active += LAGG_PORTACTIVE(lp); 1293 } |
1294 ro->ro_bkt = sc->sc_bkt; |
|
1294 ro->ro_flapping = sc->sc_flapping; 1295 ro->ro_flowid_shift = sc->flowid_shift; 1296 break; 1297 case SIOCSLAGGOPTS: | 1295 ro->ro_flapping = sc->sc_flapping; 1296 ro->ro_flowid_shift = sc->flowid_shift; 1297 break; 1298 case SIOCSLAGGOPTS: |
1299 if (sc->sc_proto == LAGG_PROTO_ROUNDROBIN) { 1300 if (ro->ro_bkt == 0) 1301 sc->sc_bkt = 1; // Minimum 1 packet per iface. 1302 else 1303 sc->sc_bkt = ro->ro_bkt; 1304 } |
|
1298 error = priv_check(td, PRIV_NET_LAGG); 1299 if (error) 1300 break; 1301 if (ro->ro_opts == 0) 1302 break; 1303 /* 1304 * Set options. LACP options are stored in sc->sc_psc, 1305 * not in sc_opts. --- 18 unchanged lines hidden (view full) --- 1324 valid = lacp = 1; 1325 break; 1326 default: 1327 valid = lacp = 0; 1328 break; 1329 } 1330 1331 LAGG_WLOCK(sc); | 1305 error = priv_check(td, PRIV_NET_LAGG); 1306 if (error) 1307 break; 1308 if (ro->ro_opts == 0) 1309 break; 1310 /* 1311 * Set options. LACP options are stored in sc->sc_psc, 1312 * not in sc_opts. --- 18 unchanged lines hidden (view full) --- 1331 valid = lacp = 1; 1332 break; 1333 default: 1334 valid = lacp = 0; 1335 break; 1336 } 1337 1338 LAGG_WLOCK(sc); |
1339 |
|
1332 if (valid == 0 || 1333 (lacp == 1 && sc->sc_proto != LAGG_PROTO_LACP)) { 1334 /* Invalid combination of options specified. */ 1335 error = EINVAL; 1336 LAGG_WUNLOCK(sc); 1337 break; /* Return from SIOCSLAGGOPTS. */ 1338 } 1339 /* --- 534 unchanged lines hidden (view full) --- 1874/* 1875 * Simple round robin aggregation 1876 */ 1877static void 1878lagg_rr_attach(struct lagg_softc *sc) 1879{ 1880 sc->sc_capabilities = IFCAP_LAGG_FULLDUPLEX; 1881 sc->sc_seq = 0; | 1340 if (valid == 0 || 1341 (lacp == 1 && sc->sc_proto != LAGG_PROTO_LACP)) { 1342 /* Invalid combination of options specified. */ 1343 error = EINVAL; 1344 LAGG_WUNLOCK(sc); 1345 break; /* Return from SIOCSLAGGOPTS. */ 1346 } 1347 /* --- 534 unchanged lines hidden (view full) --- 1882/* 1883 * Simple round robin aggregation 1884 */ 1885static void 1886lagg_rr_attach(struct lagg_softc *sc) 1887{ 1888 sc->sc_capabilities = IFCAP_LAGG_FULLDUPLEX; 1889 sc->sc_seq = 0; |
1890 sc->sc_bkt_count = sc->sc_bkt; |
|
1882} 1883 1884static int 1885lagg_rr_start(struct lagg_softc *sc, struct mbuf *m) 1886{ 1887 struct lagg_port *lp; 1888 uint32_t p; 1889 | 1891} 1892 1893static int 1894lagg_rr_start(struct lagg_softc *sc, struct mbuf *m) 1895{ 1896 struct lagg_port *lp; 1897 uint32_t p; 1898 |
1890 p = atomic_fetchadd_32(&sc->sc_seq, 1); | 1899 if (sc->sc_bkt_count == 0 && sc->sc_bkt > 0) 1900 sc->sc_bkt_count = sc->sc_bkt; 1901 1902 if (sc->sc_bkt > 0) { 1903 atomic_subtract_int(&sc->sc_bkt_count, 1); 1904 if (atomic_cmpset_int(&sc->sc_bkt_count, 0, sc->sc_bkt)) 1905 p = atomic_fetchadd_32(&sc->sc_seq, 1); 1906 else 1907 p = sc->sc_seq; 1908 } else 1909 p = atomic_fetchadd_32(&sc->sc_seq, 1); 1910 |
1891 p %= sc->sc_count; 1892 lp = SLIST_FIRST(&sc->sc_ports); | 1911 p %= sc->sc_count; 1912 lp = SLIST_FIRST(&sc->sc_ports); |
1913 |
|
1893 while (p--) 1894 lp = SLIST_NEXT(lp, lp_entries); 1895 1896 /* 1897 * Check the port's link state. This will return the next active 1898 * port if the link is down or the port is NULL. 1899 */ 1900 if ((lp = lagg_link_active(sc, lp)) == NULL) { --- 319 unchanged lines hidden --- | 1914 while (p--) 1915 lp = SLIST_NEXT(lp, lp_entries); 1916 1917 /* 1918 * Check the port's link state. This will return the next active 1919 * port if the link is down or the port is NULL. 1920 */ 1921 if ((lp = lagg_link_active(sc, lp)) == NULL) { --- 319 unchanged lines hidden --- |