2002-10-29 19:12:44 +00:00
|
|
|
/*
|
|
|
|
* ng_fec.c
|
2005-01-07 01:45:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*-
|
2002-10-29 19:12:44 +00:00
|
|
|
* Copyright (c) 2001 Berkeley Software Design, Inc.
|
|
|
|
* Copyright (c) 2000, 2001
|
|
|
|
* Bill Paul <wpaul@osd.bsdi.com>. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Bill Paul.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
2002-10-29 19:12:44 +00:00
|
|
|
* Copyright (c) 1996-1999 Whistle Communications, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Subject to the following obligations and disclaimer of warranty, use and
|
|
|
|
* redistribution of this software, in source or object code forms, with or
|
|
|
|
* without modifications are expressly permitted by Whistle Communications;
|
|
|
|
* provided, however, that:
|
|
|
|
* 1. Any and all reproductions of the source or object code must include the
|
|
|
|
* copyright notice above and the following disclaimer of warranties; and
|
|
|
|
* 2. No rights are granted, in any manner or form, to use Whistle
|
|
|
|
* Communications, Inc. trademarks, including the mark "WHISTLE
|
|
|
|
* COMMUNICATIONS" on advertising, endorsements, or otherwise except as
|
|
|
|
* such appears in the above copyright notice or in the software.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
|
|
|
|
* TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
|
|
|
|
* REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
|
|
|
|
* INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
|
|
|
* WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
|
|
|
|
* REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
|
|
|
|
* SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
|
|
|
|
* IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
|
|
|
|
* RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
|
|
|
|
* WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|
|
|
* PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
|
|
|
|
* OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Author: Archie Cobbs <archie@freebsd.org>
|
|
|
|
*
|
|
|
|
* $Whistle: ng_fec.c,v 1.33 1999/11/01 09:24:51 julian Exp $
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This module implements ethernet channel bonding using the Cisco
|
|
|
|
* Fast EtherChannel mechanism. Two or four ports may be combined
|
|
|
|
* into a single aggregate interface.
|
|
|
|
*
|
|
|
|
* Interfaces are named fec0, fec1, etc. New nodes take the
|
|
|
|
* first available interface name.
|
|
|
|
*
|
|
|
|
* This node also includes Berkeley packet filter support.
|
|
|
|
*
|
|
|
|
* Note that this node doesn't need to connect to any other
|
|
|
|
* netgraph nodes in order to do its work.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/libkern.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
2005-11-11 16:04:59 +00:00
|
|
|
#include <net/if_dl.h>
|
2002-10-29 19:12:44 +00:00
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/ethernet.h>
|
2009-04-16 20:30:28 +00:00
|
|
|
#include <net/route.h>
|
2002-10-29 19:12:44 +00:00
|
|
|
|
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "opt_inet6.h"
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet/ip6.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <netgraph/ng_message.h>
|
|
|
|
#include <netgraph/netgraph.h>
|
|
|
|
#include <netgraph/ng_parse.h>
|
|
|
|
#include <netgraph/ng_fec.h>
|
|
|
|
|
2004-06-20 19:22:22 +00:00
|
|
|
/*
|
|
|
|
* We need a way to stash a pointer to our netgraph node in the
|
|
|
|
* ifnet structure so that receive handling works. As far as I can
|
|
|
|
* tell, although there is an AF_NETGRAPH address family, it's only
|
|
|
|
* used to identify sockaddr_ng structures: there is no netgraph address
|
2004-06-20 21:08:58 +00:00
|
|
|
* family domain. This means the AF_NETGRAPH entry in ifp->if_afdata
|
|
|
|
* should be unused, so we can use to hold our node context.
|
2004-06-20 19:22:22 +00:00
|
|
|
*/
|
2005-11-09 13:34:43 +00:00
|
|
|
#define IFP2NG(ifp) ((ifp)->if_afdata[AF_NETGRAPH])
|
2002-10-29 19:12:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Current fast etherchannel implementations use either 2 or 4
|
|
|
|
* ports, so for now we limit the maximum bundle size to 4 interfaces.
|
|
|
|
*/
|
|
|
|
#define FEC_BUNDLESIZ 4
|
|
|
|
|
|
|
|
struct ng_fec_portlist {
|
|
|
|
struct ifnet *fec_if;
|
2004-06-20 21:08:58 +00:00
|
|
|
void (*fec_if_input) (struct ifnet *,
|
|
|
|
struct mbuf *);
|
2002-10-29 19:12:44 +00:00
|
|
|
int fec_idx;
|
|
|
|
int fec_ifstat;
|
|
|
|
struct ether_addr fec_mac;
|
2007-05-18 15:05:49 +00:00
|
|
|
SLIST_HEAD(__mclhd, ng_fec_mc) fec_mc_head;
|
2002-10-29 19:12:44 +00:00
|
|
|
TAILQ_ENTRY(ng_fec_portlist) fec_list;
|
|
|
|
};
|
|
|
|
|
2007-05-18 15:05:49 +00:00
|
|
|
struct ng_fec_mc {
|
|
|
|
struct ifmultiaddr *mc_ifma;
|
|
|
|
SLIST_ENTRY(ng_fec_mc) mc_entries;
|
|
|
|
};
|
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
struct ng_fec_bundle {
|
|
|
|
TAILQ_HEAD(,ng_fec_portlist) ng_fec_ports;
|
|
|
|
int fec_ifcnt;
|
|
|
|
int fec_btype;
|
2004-06-20 21:08:58 +00:00
|
|
|
int (*fec_if_output) (struct ifnet *,
|
|
|
|
struct mbuf *,
|
|
|
|
struct sockaddr *,
|
2009-04-16 20:30:28 +00:00
|
|
|
struct route *);
|
2002-10-29 19:12:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define FEC_BTYPE_MAC 0x01
|
|
|
|
#define FEC_BTYPE_INET 0x02
|
|
|
|
#define FEC_BTYPE_INET6 0x03
|
|
|
|
|
|
|
|
/* Node private data */
|
|
|
|
struct ng_fec_private {
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp;
|
2002-10-29 19:12:44 +00:00
|
|
|
struct ifmedia ifmedia;
|
|
|
|
int if_flags;
|
|
|
|
int if_error; /* XXX */
|
|
|
|
int unit; /* Interface unit number */
|
|
|
|
node_p node; /* Our netgraph node */
|
|
|
|
struct ng_fec_bundle fec_bundle;/* Aggregate bundle */
|
|
|
|
struct callout_handle fec_ch; /* callout handle for ticker */
|
|
|
|
};
|
|
|
|
typedef struct ng_fec_private *priv_p;
|
|
|
|
|
|
|
|
/* Interface methods */
|
2003-02-26 19:49:32 +00:00
|
|
|
static void ng_fec_input(struct ifnet *, struct mbuf *);
|
2002-10-29 19:12:44 +00:00
|
|
|
static void ng_fec_start(struct ifnet *ifp);
|
|
|
|
static int ng_fec_choose_port(struct ng_fec_bundle *b,
|
|
|
|
struct mbuf *m, struct ifnet **ifp);
|
|
|
|
static int ng_fec_setport(struct ifnet *ifp, u_long cmd, caddr_t data);
|
|
|
|
static void ng_fec_init(void *arg);
|
|
|
|
static void ng_fec_stop(struct ifnet *ifp);
|
|
|
|
static int ng_fec_ifmedia_upd(struct ifnet *ifp);
|
|
|
|
static void ng_fec_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr);
|
|
|
|
static int ng_fec_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
|
|
|
|
static int ng_fec_output(struct ifnet *ifp, struct mbuf *m0,
|
2009-04-16 20:30:28 +00:00
|
|
|
struct sockaddr *dst, struct route *ro);
|
2002-10-29 19:12:44 +00:00
|
|
|
static void ng_fec_tick(void *arg);
|
|
|
|
static int ng_fec_addport(struct ng_fec_private *priv, char *iface);
|
|
|
|
static int ng_fec_delport(struct ng_fec_private *priv, char *iface);
|
2007-05-18 15:05:49 +00:00
|
|
|
static int ng_fec_ether_cmdmulti(struct ifnet *trifp, struct ng_fec_portlist *p, int set);
|
2002-10-29 19:12:44 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static void ng_fec_print_ioctl(struct ifnet *ifp, int cmd, caddr_t data);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Netgraph methods */
|
2005-02-05 08:28:36 +00:00
|
|
|
static int ng_fec_mod_event(module_t, int, void *);
|
2002-10-29 19:12:44 +00:00
|
|
|
static ng_constructor_t ng_fec_constructor;
|
|
|
|
static ng_rcvmsg_t ng_fec_rcvmsg;
|
|
|
|
static ng_shutdown_t ng_fec_shutdown;
|
|
|
|
|
|
|
|
/* List of commands and how to convert arguments to/from ASCII */
|
|
|
|
static const struct ng_cmdlist ng_fec_cmds[] = {
|
|
|
|
{
|
|
|
|
NGM_FEC_COOKIE,
|
|
|
|
NGM_FEC_ADD_IFACE,
|
|
|
|
"add_iface",
|
|
|
|
&ng_parse_string_type,
|
|
|
|
NULL,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NGM_FEC_COOKIE,
|
|
|
|
NGM_FEC_DEL_IFACE,
|
|
|
|
"del_iface",
|
|
|
|
&ng_parse_string_type,
|
|
|
|
NULL,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NGM_FEC_COOKIE,
|
|
|
|
NGM_FEC_SET_MODE_MAC,
|
|
|
|
"set_mode_mac",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NGM_FEC_COOKIE,
|
|
|
|
NGM_FEC_SET_MODE_INET,
|
|
|
|
"set_mode_inet",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
},
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Node type descriptor */
|
|
|
|
static struct ng_type typestruct = {
|
2004-05-29 00:51:19 +00:00
|
|
|
.version = NG_ABI_VERSION,
|
|
|
|
.name = NG_FEC_NODE_TYPE,
|
2005-02-05 08:28:36 +00:00
|
|
|
.mod_event = ng_fec_mod_event,
|
2004-05-29 00:51:19 +00:00
|
|
|
.constructor = ng_fec_constructor,
|
|
|
|
.rcvmsg = ng_fec_rcvmsg,
|
|
|
|
.shutdown = ng_fec_shutdown,
|
|
|
|
.cmdlist = ng_fec_cmds,
|
2002-10-29 19:12:44 +00:00
|
|
|
};
|
|
|
|
NETGRAPH_INIT(fec, &typestruct);
|
|
|
|
|
|
|
|
/* We keep a bitmap indicating which unit numbers are free.
|
|
|
|
One means the unit number is free, zero means it's taken. */
|
|
|
|
static int *ng_fec_units = NULL;
|
|
|
|
static int ng_fec_units_len = 0;
|
|
|
|
static int ng_units_in_use = 0;
|
|
|
|
|
|
|
|
#define UNITS_BITSPERWORD (sizeof(*ng_fec_units) * NBBY)
|
|
|
|
|
2004-07-14 20:27:33 +00:00
|
|
|
static struct mtx ng_fec_mtx;
|
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
/*
|
|
|
|
* Find the first free unit number for a new interface.
|
|
|
|
* Increase the size of the unit bitmap as necessary.
|
|
|
|
*/
|
2004-07-04 16:11:03 +00:00
|
|
|
static __inline int
|
2002-10-29 19:12:44 +00:00
|
|
|
ng_fec_get_unit(int *unit)
|
|
|
|
{
|
|
|
|
int index, bit;
|
|
|
|
|
2004-07-14 20:27:33 +00:00
|
|
|
mtx_lock(&ng_fec_mtx);
|
2002-10-29 19:12:44 +00:00
|
|
|
for (index = 0; index < ng_fec_units_len
|
|
|
|
&& ng_fec_units[index] == 0; index++);
|
|
|
|
if (index == ng_fec_units_len) { /* extend array */
|
|
|
|
int i, *newarray, newlen;
|
|
|
|
|
|
|
|
newlen = (2 * ng_fec_units_len) + 4;
|
2008-10-23 15:53:51 +00:00
|
|
|
newarray = malloc(newlen * sizeof(*ng_fec_units),
|
2002-10-29 19:12:44 +00:00
|
|
|
M_NETGRAPH, M_NOWAIT);
|
2004-07-14 20:27:33 +00:00
|
|
|
if (newarray == NULL) {
|
|
|
|
mtx_unlock(&ng_fec_mtx);
|
2002-10-29 19:12:44 +00:00
|
|
|
return (ENOMEM);
|
2004-07-14 20:27:33 +00:00
|
|
|
}
|
2002-10-29 19:12:44 +00:00
|
|
|
bcopy(ng_fec_units, newarray,
|
|
|
|
ng_fec_units_len * sizeof(*ng_fec_units));
|
|
|
|
for (i = ng_fec_units_len; i < newlen; i++)
|
|
|
|
newarray[i] = ~0;
|
|
|
|
if (ng_fec_units != NULL)
|
2008-10-23 15:53:51 +00:00
|
|
|
free(ng_fec_units, M_NETGRAPH);
|
2002-10-29 19:12:44 +00:00
|
|
|
ng_fec_units = newarray;
|
|
|
|
ng_fec_units_len = newlen;
|
|
|
|
}
|
|
|
|
bit = ffs(ng_fec_units[index]) - 1;
|
|
|
|
KASSERT(bit >= 0 && bit <= UNITS_BITSPERWORD - 1,
|
2005-08-10 06:25:41 +00:00
|
|
|
("%s: word=%d bit=%d", __func__, ng_fec_units[index], bit));
|
2002-10-29 19:12:44 +00:00
|
|
|
ng_fec_units[index] &= ~(1 << bit);
|
|
|
|
*unit = (index * UNITS_BITSPERWORD) + bit;
|
|
|
|
ng_units_in_use++;
|
2004-07-14 20:27:33 +00:00
|
|
|
mtx_unlock(&ng_fec_mtx);
|
2002-10-29 19:12:44 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free a no longer needed unit number.
|
|
|
|
*/
|
2004-07-04 16:11:03 +00:00
|
|
|
static __inline void
|
2002-10-29 19:12:44 +00:00
|
|
|
ng_fec_free_unit(int unit)
|
|
|
|
{
|
|
|
|
int index, bit;
|
|
|
|
|
|
|
|
index = unit / UNITS_BITSPERWORD;
|
|
|
|
bit = unit % UNITS_BITSPERWORD;
|
2004-07-14 20:27:33 +00:00
|
|
|
mtx_lock(&ng_fec_mtx);
|
2002-10-29 19:12:44 +00:00
|
|
|
KASSERT(index < ng_fec_units_len,
|
2005-08-10 06:25:41 +00:00
|
|
|
("%s: unit=%d len=%d", __func__, unit, ng_fec_units_len));
|
2002-10-29 19:12:44 +00:00
|
|
|
KASSERT((ng_fec_units[index] & (1 << bit)) == 0,
|
2005-08-10 06:25:41 +00:00
|
|
|
("%s: unit=%d is free", __func__, unit));
|
2002-10-29 19:12:44 +00:00
|
|
|
ng_fec_units[index] |= (1 << bit);
|
|
|
|
/*
|
|
|
|
* XXX We could think about reducing the size of ng_fec_units[]
|
|
|
|
* XXX here if the last portion is all ones
|
|
|
|
* XXX At least free it if no more units
|
|
|
|
* Needed if we are to eventually be able to unload.
|
|
|
|
*/
|
|
|
|
ng_units_in_use--;
|
|
|
|
if (ng_units_in_use == 0) { /* XXX make SMP safe */
|
2008-10-23 15:53:51 +00:00
|
|
|
free(ng_fec_units, M_NETGRAPH);
|
2002-10-29 19:12:44 +00:00
|
|
|
ng_fec_units_len = 0;
|
|
|
|
ng_fec_units = NULL;
|
|
|
|
}
|
2004-07-14 20:27:33 +00:00
|
|
|
mtx_unlock(&ng_fec_mtx);
|
2002-10-29 19:12:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
INTERFACE STUFF
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
ng_fec_addport(struct ng_fec_private *priv, char *iface)
|
|
|
|
{
|
|
|
|
struct ng_fec_bundle *b;
|
|
|
|
struct ifnet *ifp, *bifp;
|
|
|
|
struct ng_fec_portlist *p, *new;
|
|
|
|
|
|
|
|
if (priv == NULL || iface == NULL)
|
|
|
|
return(EINVAL);
|
|
|
|
|
|
|
|
b = &priv->fec_bundle;
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = priv->ifp;
|
2002-10-29 19:12:44 +00:00
|
|
|
|
2005-11-04 15:42:01 +00:00
|
|
|
/* Only allow reconfiguration if not running. */
|
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
|
|
|
printf("fec%d: can't add new iface; bundle is running\n",
|
|
|
|
priv->unit);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
/* Find the interface */
|
|
|
|
bifp = ifunit(iface);
|
|
|
|
if (bifp == NULL) {
|
|
|
|
printf("fec%d: tried to add iface %s, which "
|
|
|
|
"doesn't seem to exist\n", priv->unit, iface);
|
|
|
|
return(ENOENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See if we have room in the bundle */
|
|
|
|
if (b->fec_ifcnt == FEC_BUNDLESIZ) {
|
|
|
|
printf("fec%d: can't add new iface; bundle is full\n",
|
|
|
|
priv->unit);
|
|
|
|
return(ENOSPC);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See if the interface is already in the bundle */
|
|
|
|
TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) {
|
|
|
|
if (p->fec_if == bifp) {
|
|
|
|
printf("fec%d: iface %s is already in this "
|
|
|
|
"bundle\n", priv->unit, iface);
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-20 21:08:58 +00:00
|
|
|
/*
|
|
|
|
* All interfaces must use the same output vector. Once the
|
|
|
|
* user attaches an interface of one type, make all subsequent
|
|
|
|
* interfaces have the same output vector.
|
|
|
|
*/
|
|
|
|
if (b->fec_if_output != NULL) {
|
|
|
|
if (b->fec_if_output != bifp->if_output) {
|
|
|
|
printf("fec%d: iface %s is not the same type "
|
|
|
|
"as the other interface(s) already in "
|
|
|
|
"the bundle\n", priv->unit, iface);
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
/* Allocate new list entry. */
|
2008-10-23 20:26:15 +00:00
|
|
|
new = malloc(sizeof(struct ng_fec_portlist), M_NETGRAPH, M_NOWAIT);
|
2002-10-29 19:12:44 +00:00
|
|
|
if (new == NULL)
|
|
|
|
return(ENOMEM);
|
|
|
|
|
2004-06-20 19:22:22 +00:00
|
|
|
IF_AFDATA_LOCK(bifp);
|
2005-11-09 13:34:43 +00:00
|
|
|
IFP2NG(bifp) = priv->node;
|
2004-06-20 19:22:22 +00:00
|
|
|
IF_AFDATA_UNLOCK(bifp);
|
2002-10-29 19:12:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is the first interface added to the bundle,
|
|
|
|
* use its MAC address for the virtual interface (and,
|
|
|
|
* by extension, all the other ports in the bundle).
|
|
|
|
*/
|
2005-11-04 16:29:51 +00:00
|
|
|
if (b->fec_ifcnt == 0)
|
2005-11-11 16:04:59 +00:00
|
|
|
if_setlladdr(ifp, IF_LLADDR(bifp), ETHER_ADDR_LEN);
|
2002-10-29 19:12:44 +00:00
|
|
|
|
|
|
|
b->fec_btype = FEC_BTYPE_MAC;
|
|
|
|
new->fec_idx = b->fec_ifcnt;
|
|
|
|
b->fec_ifcnt++;
|
|
|
|
|
2007-05-18 15:05:49 +00:00
|
|
|
/* Initialise the list of multicast addresses that we own. */
|
|
|
|
SLIST_INIT(&new->fec_mc_head);
|
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
/* Save the real MAC address. */
|
2005-11-11 16:04:59 +00:00
|
|
|
bcopy(IF_LLADDR(bifp),
|
2002-10-29 19:12:44 +00:00
|
|
|
(char *)&new->fec_mac, ETHER_ADDR_LEN);
|
|
|
|
|
|
|
|
/* Set up phony MAC address. */
|
2005-11-11 16:04:59 +00:00
|
|
|
if_setlladdr(bifp, IF_LLADDR(ifp), ETHER_ADDR_LEN);
|
2002-10-29 19:12:44 +00:00
|
|
|
|
2003-02-26 19:49:32 +00:00
|
|
|
/* Save original input vector */
|
|
|
|
new->fec_if_input = bifp->if_input;
|
|
|
|
|
|
|
|
/* Override it with our own */
|
|
|
|
bifp->if_input = ng_fec_input;
|
|
|
|
|
2004-06-20 21:08:58 +00:00
|
|
|
/* Save output vector too. */
|
|
|
|
if (b->fec_if_output == NULL)
|
|
|
|
b->fec_if_output = bifp->if_output;
|
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
/* Add to the queue */
|
|
|
|
new->fec_if = bifp;
|
2005-11-04 15:42:01 +00:00
|
|
|
new->fec_ifstat = -1;
|
2002-10-29 19:12:44 +00:00
|
|
|
TAILQ_INSERT_TAIL(&b->ng_fec_ports, new, fec_list);
|
|
|
|
|
2007-05-18 15:05:49 +00:00
|
|
|
/* Add multicast addresses to this port. */
|
|
|
|
ng_fec_ether_cmdmulti(ifp, new, 1);
|
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ng_fec_delport(struct ng_fec_private *priv, char *iface)
|
|
|
|
{
|
|
|
|
struct ng_fec_bundle *b;
|
|
|
|
struct ifnet *ifp, *bifp;
|
|
|
|
struct ng_fec_portlist *p;
|
|
|
|
|
|
|
|
if (priv == NULL || iface == NULL)
|
|
|
|
return(EINVAL);
|
|
|
|
|
|
|
|
b = &priv->fec_bundle;
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = priv->ifp;
|
2002-10-29 19:12:44 +00:00
|
|
|
|
2005-11-04 15:42:01 +00:00
|
|
|
/* Only allow reconfiguration if not running. */
|
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
|
|
|
printf("fec%d: can't remove iface; bundle is running\n",
|
|
|
|
priv->unit);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
/* Find the interface */
|
|
|
|
bifp = ifunit(iface);
|
|
|
|
if (bifp == NULL) {
|
|
|
|
printf("fec%d: tried to remove iface %s, which "
|
|
|
|
"doesn't seem to exist\n", priv->unit, iface);
|
|
|
|
return(ENOENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) {
|
|
|
|
if (p->fec_if == bifp)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p == NULL) {
|
|
|
|
printf("fec%d: tried to remove iface %s which "
|
|
|
|
"is not in our bundle\n", priv->unit, iface);
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop interface */
|
|
|
|
bifp->if_flags &= ~IFF_UP;
|
|
|
|
(*bifp->if_ioctl)(bifp, SIOCSIFFLAGS, NULL);
|
|
|
|
|
|
|
|
/* Restore MAC address. */
|
2005-11-04 16:29:51 +00:00
|
|
|
if_setlladdr(bifp, (u_char *)&p->fec_mac, ETHER_ADDR_LEN);
|
2002-10-29 19:12:44 +00:00
|
|
|
|
2003-02-26 19:49:32 +00:00
|
|
|
/* Restore input vector */
|
|
|
|
bifp->if_input = p->fec_if_input;
|
|
|
|
|
2004-06-20 19:22:22 +00:00
|
|
|
/* Remove our node context pointer. */
|
|
|
|
IF_AFDATA_LOCK(bifp);
|
2005-11-09 13:34:43 +00:00
|
|
|
IFP2NG(bifp) = NULL;
|
2004-06-20 19:22:22 +00:00
|
|
|
IF_AFDATA_UNLOCK(bifp);
|
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
/* Delete port */
|
|
|
|
TAILQ_REMOVE(&b->ng_fec_ports, p, fec_list);
|
2008-10-23 15:53:51 +00:00
|
|
|
free(p, M_NETGRAPH);
|
2002-10-29 19:12:44 +00:00
|
|
|
b->fec_ifcnt--;
|
|
|
|
|
2004-06-20 21:08:58 +00:00
|
|
|
if (b->fec_ifcnt == 0)
|
|
|
|
b->fec_if_output = NULL;
|
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2007-05-18 15:05:49 +00:00
|
|
|
static int
|
|
|
|
ng_fec_ether_cmdmulti(struct ifnet *trifp, struct ng_fec_portlist *p, int set)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = p->fec_if;
|
|
|
|
struct ng_fec_mc *mc;
|
|
|
|
struct ifmultiaddr *ifma, *rifma = NULL;
|
|
|
|
struct sockaddr_dl sdl;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
bzero((char *)&sdl, sizeof(sdl));
|
|
|
|
sdl.sdl_len = sizeof(sdl);
|
|
|
|
sdl.sdl_family = AF_LINK;
|
|
|
|
sdl.sdl_type = IFT_ETHER;
|
|
|
|
sdl.sdl_alen = ETHER_ADDR_LEN;
|
|
|
|
sdl.sdl_index = ifp->if_index;
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
TAILQ_FOREACH(ifma, &trifp->if_multiaddrs, ifma_link) {
|
|
|
|
if (ifma->ifma_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
|
|
|
bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
|
|
|
|
LLADDR(&sdl), ETHER_ADDR_LEN);
|
|
|
|
|
|
|
|
error = if_addmulti(ifp, (struct sockaddr *)&sdl, &rifma);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
mc = malloc(sizeof(struct ng_fec_mc), M_DEVBUF, M_NOWAIT);
|
|
|
|
if (mc == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
mc->mc_ifma = rifma;
|
|
|
|
SLIST_INSERT_HEAD(&p->fec_mc_head, mc, mc_entries);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while ((mc = SLIST_FIRST(&p->fec_mc_head)) != NULL) {
|
|
|
|
SLIST_REMOVE(&p->fec_mc_head, mc, ng_fec_mc, mc_entries);
|
|
|
|
if_delmulti_ifma(mc->mc_ifma);
|
|
|
|
free(mc, M_DEVBUF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ng_fec_ether_setmulti(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct ng_fec_private *priv;
|
|
|
|
struct ng_fec_bundle *b;
|
|
|
|
struct ng_fec_portlist *p;
|
|
|
|
|
|
|
|
priv = ifp->if_softc;
|
|
|
|
b = &priv->fec_bundle;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) {
|
|
|
|
/* First, remove any existing filter entries. */
|
|
|
|
ng_fec_ether_cmdmulti(ifp, p, 0);
|
|
|
|
/* copy all addresses from the fec interface to the port */
|
|
|
|
ng_fec_ether_cmdmulti(ifp, p, 1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
/*
|
|
|
|
* Pass an ioctl command down to all the underyling interfaces in a
|
2007-05-18 15:05:49 +00:00
|
|
|
* bundle. Used for setting flags.
|
2002-10-29 19:12:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
ng_fec_setport(struct ifnet *ifp, u_long command, caddr_t data)
|
|
|
|
{
|
|
|
|
struct ng_fec_private *priv;
|
|
|
|
struct ng_fec_bundle *b;
|
|
|
|
struct ifnet *oifp;
|
|
|
|
struct ng_fec_portlist *p;
|
|
|
|
|
|
|
|
priv = ifp->if_softc;
|
|
|
|
b = &priv->fec_bundle;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) {
|
|
|
|
oifp = p->fec_if;
|
|
|
|
if (oifp != NULL)
|
|
|
|
(*oifp->if_ioctl)(oifp, command, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ng_fec_init(void *arg)
|
|
|
|
{
|
|
|
|
struct ng_fec_private *priv;
|
|
|
|
struct ng_fec_bundle *b;
|
|
|
|
struct ifnet *ifp, *bifp;
|
|
|
|
struct ng_fec_portlist *p;
|
|
|
|
|
2005-08-25 17:00:02 +00:00
|
|
|
priv = arg;
|
|
|
|
ifp = priv->ifp;
|
2002-10-29 19:12:44 +00:00
|
|
|
b = &priv->fec_bundle;
|
|
|
|
|
2005-11-04 15:42:01 +00:00
|
|
|
if (b->fec_ifcnt != 2 && b->fec_ifcnt != FEC_BUNDLESIZ) {
|
2002-10-29 19:12:44 +00:00
|
|
|
printf("fec%d: invalid bundle "
|
|
|
|
"size: %d\n", priv->unit,
|
|
|
|
b->fec_ifcnt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ng_fec_stop(ifp);
|
|
|
|
|
|
|
|
TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) {
|
|
|
|
bifp = p->fec_if;
|
|
|
|
bifp->if_flags |= IFF_UP;
|
|
|
|
(*bifp->if_ioctl)(bifp, SIOCSIFFLAGS, NULL);
|
|
|
|
/* mark iface as up and let the monitor check it */
|
|
|
|
p->fec_ifstat = -1;
|
|
|
|
}
|
|
|
|
|
2005-11-04 13:50:38 +00:00
|
|
|
ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE);
|
|
|
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
priv->fec_ch = timeout(ng_fec_tick, priv, hz);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ng_fec_stop(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct ng_fec_private *priv;
|
|
|
|
struct ng_fec_bundle *b;
|
|
|
|
struct ifnet *bifp;
|
|
|
|
struct ng_fec_portlist *p;
|
|
|
|
|
|
|
|
priv = ifp->if_softc;
|
|
|
|
b = &priv->fec_bundle;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) {
|
|
|
|
bifp = p->fec_if;
|
|
|
|
bifp->if_flags &= ~IFF_UP;
|
|
|
|
(*bifp->if_ioctl)(bifp, SIOCSIFFLAGS, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
untimeout(ng_fec_tick, priv, priv->fec_ch);
|
|
|
|
|
2005-11-04 13:50:38 +00:00
|
|
|
ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
|
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ng_fec_tick(void *arg)
|
|
|
|
{
|
|
|
|
struct ng_fec_private *priv;
|
|
|
|
struct ng_fec_bundle *b;
|
|
|
|
struct ifmediareq ifmr;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ng_fec_portlist *p;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
priv = arg;
|
|
|
|
b = &priv->fec_bundle;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) {
|
|
|
|
bzero((char *)&ifmr, sizeof(ifmr));
|
|
|
|
ifp = p->fec_if;
|
|
|
|
error = (*ifp->if_ioctl)(ifp, SIOCGIFMEDIA, (caddr_t)&ifmr);
|
|
|
|
if (error) {
|
|
|
|
printf("fec%d: failed to check status "
|
2003-10-31 18:32:15 +00:00
|
|
|
"of link %s\n", priv->unit, ifp->if_xname);
|
2002-10-29 19:12:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-06-20 21:08:58 +00:00
|
|
|
if (ifmr.ifm_status & IFM_AVALID) {
|
2002-10-29 19:12:44 +00:00
|
|
|
if (ifmr.ifm_status & IFM_ACTIVE) {
|
|
|
|
if (p->fec_ifstat == -1 ||
|
|
|
|
p->fec_ifstat == 0) {
|
|
|
|
p->fec_ifstat = 1;
|
2003-10-31 18:32:15 +00:00
|
|
|
printf("fec%d: port %s in bundle "
|
2002-10-29 19:12:44 +00:00
|
|
|
"is up\n", priv->unit,
|
2003-10-31 18:32:15 +00:00
|
|
|
ifp->if_xname);
|
2002-10-29 19:12:44 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (p->fec_ifstat == -1 ||
|
|
|
|
p->fec_ifstat == 1) {
|
|
|
|
p->fec_ifstat = 0;
|
2003-10-31 18:32:15 +00:00
|
|
|
printf("fec%d: port %s in bundle "
|
2002-10-29 19:12:44 +00:00
|
|
|
"is down\n", priv->unit,
|
2003-10-31 18:32:15 +00:00
|
|
|
ifp->if_xname);
|
2002-10-29 19:12:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = priv->ifp;
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING)
|
2002-10-29 19:12:44 +00:00
|
|
|
priv->fec_ch = timeout(ng_fec_tick, priv, hz);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ng_fec_ifmedia_upd(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ng_fec_ifmedia_sts(struct ifnet *ifp,
|
|
|
|
struct ifmediareq *ifmr)
|
|
|
|
{
|
|
|
|
struct ng_fec_private *priv;
|
|
|
|
struct ng_fec_bundle *b;
|
|
|
|
struct ng_fec_portlist *p;
|
|
|
|
|
|
|
|
priv = ifp->if_softc;
|
|
|
|
b = &priv->fec_bundle;
|
|
|
|
|
|
|
|
ifmr->ifm_status = IFM_AVALID;
|
|
|
|
TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) {
|
2005-11-04 15:42:01 +00:00
|
|
|
if (p->fec_ifstat == 1) {
|
2002-10-29 19:12:44 +00:00
|
|
|
ifmr->ifm_status |= IFM_ACTIVE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an ioctl for the virtual interface
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_fec_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
|
|
|
|
{
|
|
|
|
struct ifreq *const ifr = (struct ifreq *) data;
|
|
|
|
int s, error = 0;
|
|
|
|
struct ng_fec_private *priv;
|
|
|
|
struct ng_fec_bundle *b;
|
|
|
|
|
|
|
|
priv = ifp->if_softc;
|
|
|
|
b = &priv->fec_bundle;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
ng_fec_print_ioctl(ifp, command, data);
|
|
|
|
#endif
|
|
|
|
s = splimp();
|
|
|
|
switch (command) {
|
|
|
|
|
|
|
|
/* These two are mostly handled at a higher layer */
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
case SIOCGIFADDR:
|
|
|
|
error = ether_ioctl(ifp, command, data);
|
|
|
|
break;
|
|
|
|
|
2006-09-15 16:06:27 +00:00
|
|
|
case SIOCSIFMTU:
|
|
|
|
if (ifr->ifr_mtu >= NG_FEC_MTU_MIN &&
|
|
|
|
ifr->ifr_mtu <= NG_FEC_MTU_MAX) {
|
|
|
|
struct ng_fec_portlist *p;
|
|
|
|
struct ifnet *bifp;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) {
|
|
|
|
bifp = p->fec_if;
|
|
|
|
error = (*bifp->if_ioctl)(bifp, SIOCSIFMTU,
|
|
|
|
data);
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (error == 0)
|
|
|
|
ifp->if_mtu = ifr->ifr_mtu;
|
|
|
|
} else
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
/* Set flags */
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
/*
|
|
|
|
* If the interface is marked up and stopped, then start it.
|
|
|
|
* If it is marked down and running, then stop it.
|
|
|
|
*/
|
|
|
|
if (ifr->ifr_flags & IFF_UP) {
|
2005-08-09 10:20:02 +00:00
|
|
|
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
|
2002-10-29 19:12:44 +00:00
|
|
|
/* Sanity. */
|
2005-11-04 15:42:01 +00:00
|
|
|
if (b->fec_ifcnt != 2 &&
|
|
|
|
b->fec_ifcnt != FEC_BUNDLESIZ) {
|
2002-10-29 19:12:44 +00:00
|
|
|
printf("fec%d: invalid bundle "
|
|
|
|
"size: %d\n", priv->unit,
|
|
|
|
b->fec_ifcnt);
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2005-08-25 17:00:02 +00:00
|
|
|
ng_fec_init(priv);
|
2002-10-29 19:12:44 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Bubble down changes in promisc mode to
|
|
|
|
* underlying interfaces.
|
|
|
|
*/
|
|
|
|
if ((ifp->if_flags & IFF_PROMISC) !=
|
|
|
|
(priv->if_flags & IFF_PROMISC)) {
|
|
|
|
ng_fec_setport(ifp, command, data);
|
|
|
|
priv->if_flags = ifp->if_flags;
|
|
|
|
}
|
|
|
|
} else {
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING)
|
2005-11-04 13:50:38 +00:00
|
|
|
ng_fec_stop(ifp);
|
2002-10-29 19:12:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
2007-05-18 15:05:49 +00:00
|
|
|
ng_fec_ether_setmulti(ifp);
|
2002-10-29 19:12:44 +00:00
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &priv->ifmedia, command);
|
|
|
|
break;
|
|
|
|
/* Stuff that's not supported */
|
|
|
|
case SIOCSIFPHYS:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
(void) splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-02-26 19:49:32 +00:00
|
|
|
* This routine spies on mbufs received by underlying network device
|
|
|
|
* drivers. When we add an interface to our bundle, we override its
|
|
|
|
* if_input routine with a pointer to ng_fec_input(). This means we
|
|
|
|
* get to look at all the device's packets before sending them to the
|
|
|
|
* real ether_input() for processing by the stack. Once we verify the
|
|
|
|
* packet comes from an interface that's been aggregated into
|
|
|
|
* our bundle, we fix up the rcvif pointer and increment our
|
2002-10-29 19:12:44 +00:00
|
|
|
* packet counters so that it looks like the frames are actually
|
|
|
|
* coming from us.
|
|
|
|
*/
|
|
|
|
static void
|
2003-02-26 19:49:32 +00:00
|
|
|
ng_fec_input(struct ifnet *ifp, struct mbuf *m0)
|
2002-10-29 19:12:44 +00:00
|
|
|
{
|
|
|
|
struct ng_node *node;
|
|
|
|
struct ng_fec_private *priv;
|
|
|
|
struct ng_fec_bundle *b;
|
|
|
|
struct ifnet *bifp;
|
|
|
|
struct ng_fec_portlist *p;
|
|
|
|
|
|
|
|
/* Sanity check */
|
2003-02-26 06:38:54 +00:00
|
|
|
if (ifp == NULL || m0 == NULL)
|
2002-10-29 19:12:44 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
node = IFP2NG(ifp);
|
|
|
|
|
|
|
|
/* Sanity check part II */
|
|
|
|
if (node == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv = NG_NODE_PRIVATE(node);
|
|
|
|
b = &priv->fec_bundle;
|
2005-06-10 16:49:24 +00:00
|
|
|
bifp = priv->ifp;
|
2002-10-29 19:12:44 +00:00
|
|
|
|
|
|
|
TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) {
|
2003-02-26 19:49:32 +00:00
|
|
|
if (p->fec_if == m0->m_pkthdr.rcvif)
|
2002-10-29 19:12:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wasn't meant for us; leave this frame alone. */
|
|
|
|
if (p == NULL)
|
|
|
|
return;
|
|
|
|
|
2003-02-26 19:49:32 +00:00
|
|
|
/*
|
|
|
|
* Check for a BPF tap on the underlying interface. This
|
|
|
|
* is mainly a debugging aid: it allows tcpdump-ing of an
|
|
|
|
* individual interface in a bundle to work, which it
|
|
|
|
* otherwise would not. BPF tapping of our own aggregate
|
|
|
|
* interface will occur once we call ether_input().
|
|
|
|
*/
|
|
|
|
BPF_MTAP(m0->m_pkthdr.rcvif, m0);
|
|
|
|
|
|
|
|
/* Convince the system that this is our frame. */
|
|
|
|
m0->m_pkthdr.rcvif = bifp;
|
2002-10-29 19:12:44 +00:00
|
|
|
|
2006-09-15 20:17:45 +00:00
|
|
|
/*
|
|
|
|
* Count bytes on an individual interface in a bundle.
|
|
|
|
* The bytes will also be added to the aggregate interface
|
|
|
|
* once we call ether_input().
|
|
|
|
*/
|
|
|
|
ifp->if_ibytes += m0->m_pkthdr.len;
|
|
|
|
|
|
|
|
bifp->if_ipackets++;
|
2003-02-26 19:49:32 +00:00
|
|
|
(*bifp->if_input)(bifp, m0);
|
2002-10-29 19:12:44 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take a quick peek at the packet and see if it's ok for us to use
|
|
|
|
* the inet or inet6 hash methods on it, if they're enabled. We do
|
|
|
|
* this by setting flags in the mbuf header. Once we've made up our
|
2004-06-20 21:08:58 +00:00
|
|
|
* mind what to do, we pass the frame to output vector for further
|
2002-10-29 19:12:44 +00:00
|
|
|
* processing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
ng_fec_output(struct ifnet *ifp, struct mbuf *m,
|
2009-04-16 20:30:28 +00:00
|
|
|
struct sockaddr *dst, struct route *ro)
|
2002-10-29 19:12:44 +00:00
|
|
|
{
|
|
|
|
const priv_p priv = (priv_p) ifp->if_softc;
|
|
|
|
struct ng_fec_bundle *b;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* Check interface flags */
|
2005-08-09 10:20:02 +00:00
|
|
|
if (!((ifp->if_flags & IFF_UP) &&
|
|
|
|
(ifp->if_drv_flags & IFF_DRV_RUNNING))) {
|
2002-10-29 19:12:44 +00:00
|
|
|
m_freem(m);
|
|
|
|
return (ENETDOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
b = &priv->fec_bundle;
|
|
|
|
|
|
|
|
switch (b->fec_btype) {
|
|
|
|
case FEC_BTYPE_MAC:
|
|
|
|
m->m_flags |= M_FEC_MAC;
|
|
|
|
break;
|
|
|
|
#ifdef INET
|
|
|
|
case FEC_BTYPE_INET:
|
|
|
|
/*
|
|
|
|
* We can't use the INET address port selection
|
|
|
|
* scheme if this isn't an INET packet.
|
|
|
|
*/
|
|
|
|
if (dst->sa_family == AF_INET)
|
|
|
|
m->m_flags |= M_FEC_INET;
|
|
|
|
#ifdef INET6
|
|
|
|
else if (dst->sa_family == AF_INET6)
|
|
|
|
m->m_flags |= M_FEC_INET6;
|
|
|
|
#endif
|
|
|
|
else {
|
|
|
|
#ifdef DEBUG
|
2003-10-31 18:32:15 +00:00
|
|
|
if_printf(ifp, "can't do inet aggregation of non "
|
|
|
|
"inet packet\n");
|
2002-10-29 19:12:44 +00:00
|
|
|
#endif
|
|
|
|
m->m_flags |= M_FEC_MAC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2003-10-31 18:32:15 +00:00
|
|
|
if_printf(ifp, "bogus hash type: %d\n",
|
2002-10-29 19:12:44 +00:00
|
|
|
b->fec_btype);
|
|
|
|
m_freem(m);
|
|
|
|
return(EINVAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-06-20 21:08:58 +00:00
|
|
|
* Pass the frame to the output vector for all the protocol
|
2002-10-29 19:12:44 +00:00
|
|
|
* handling. This will put the ethernet header on the packet
|
|
|
|
* for us.
|
|
|
|
*/
|
|
|
|
priv->if_error = 0;
|
2009-04-16 20:30:28 +00:00
|
|
|
error = (*b->fec_if_output)(ifp, m, dst, ro);
|
2002-10-29 19:12:44 +00:00
|
|
|
if (priv->if_error && !error)
|
|
|
|
error = priv->if_error;
|
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Apply a hash to the source and destination addresses in the packet
|
|
|
|
* in order to select an interface. Also check link status and handle
|
|
|
|
* dead links accordingly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
ng_fec_choose_port(struct ng_fec_bundle *b,
|
|
|
|
struct mbuf *m, struct ifnet **ifp)
|
|
|
|
{
|
|
|
|
struct ether_header *eh;
|
|
|
|
struct mbuf *m0;
|
|
|
|
#ifdef INET
|
|
|
|
struct ip *ip;
|
|
|
|
#ifdef INET6
|
|
|
|
struct ip6_hdr *ip6;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct ng_fec_portlist *p;
|
|
|
|
int port = 0, mask;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there are only two ports, mask off all but the
|
|
|
|
* last bit for XORing. If there are 4, mask off all
|
|
|
|
* but the last 2 bits.
|
|
|
|
*/
|
|
|
|
mask = b->fec_ifcnt == 2 ? 0x1 : 0x3;
|
|
|
|
eh = mtod(m, struct ether_header *);
|
|
|
|
#ifdef INET
|
|
|
|
ip = (struct ip *)(mtod(m, char *) +
|
|
|
|
sizeof(struct ether_header));
|
|
|
|
#ifdef INET6
|
|
|
|
ip6 = (struct ip6_hdr *)(mtod(m, char *) +
|
|
|
|
sizeof(struct ether_header));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The fg_fec_output() routine is supposed to leave a
|
|
|
|
* flag for us in the mbuf that tells us what hash to
|
|
|
|
* use, but sometimes a new mbuf is prepended to the
|
|
|
|
* chain, so we have to search every mbuf in the chain
|
|
|
|
* to find the flags.
|
|
|
|
*/
|
|
|
|
m0 = m;
|
|
|
|
while (m0) {
|
|
|
|
if (m0->m_flags & (M_FEC_MAC|M_FEC_INET|M_FEC_INET6))
|
|
|
|
break;
|
|
|
|
m0 = m0->m_next;
|
|
|
|
}
|
|
|
|
if (m0 == NULL)
|
|
|
|
return(EINVAL);
|
|
|
|
|
|
|
|
switch (m0->m_flags & (M_FEC_MAC|M_FEC_INET|M_FEC_INET6)) {
|
|
|
|
case M_FEC_MAC:
|
|
|
|
port = (eh->ether_dhost[5] ^
|
|
|
|
eh->ether_shost[5]) & mask;
|
|
|
|
break;
|
|
|
|
#ifdef INET
|
|
|
|
case M_FEC_INET:
|
|
|
|
port = (ntohl(ip->ip_dst.s_addr) ^
|
|
|
|
ntohl(ip->ip_src.s_addr)) & mask;
|
|
|
|
break;
|
|
|
|
#ifdef INET6
|
|
|
|
case M_FEC_INET6:
|
|
|
|
port = (ip6->ip6_dst.s6_addr[15] ^
|
|
|
|
ip6->ip6_dst.s6_addr[15]) & mask;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return(EINVAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) {
|
|
|
|
if (port == p->fec_idx)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that we've chosen a port, make sure it's
|
|
|
|
* alive. If it's not alive, cycle through the bundle
|
|
|
|
* looking for a port that is alive. If we don't find
|
|
|
|
* any, return an error.
|
|
|
|
*/
|
|
|
|
if (p->fec_ifstat != 1) {
|
|
|
|
struct ng_fec_portlist *n = NULL;
|
|
|
|
|
|
|
|
n = TAILQ_NEXT(p, fec_list);
|
|
|
|
if (n == NULL)
|
|
|
|
n = TAILQ_FIRST(&b->ng_fec_ports);
|
|
|
|
while (n != p) {
|
|
|
|
if (n->fec_ifstat == 1)
|
|
|
|
break;
|
|
|
|
n = TAILQ_NEXT(n, fec_list);
|
|
|
|
if (n == NULL)
|
|
|
|
n = TAILQ_FIRST(&b->ng_fec_ports);
|
|
|
|
}
|
|
|
|
if (n == p)
|
|
|
|
return(EAGAIN);
|
|
|
|
p = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ifp = p->fec_if;
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that the packet has been run through ether_output(), yank it
|
|
|
|
* off our own send queue and stick it on the queue for the appropriate
|
|
|
|
* underlying physical interface. Note that if the interface's send
|
|
|
|
* queue is full, we save an error status in our private netgraph
|
|
|
|
* space which will eventually be handed up to ng_fec_output(), which
|
|
|
|
* will return it to the rest of the IP stack. We need to do this
|
|
|
|
* in order to duplicate the effect of ether_output() returning ENOBUFS
|
|
|
|
* when it detects that an interface's send queue is full. There's no
|
|
|
|
* other way to signal the error status from here since the if_start()
|
|
|
|
* routine is spec'ed to return void.
|
|
|
|
*
|
|
|
|
* Once the frame is queued, we call ether_output_frame() to initiate
|
|
|
|
* transmission.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ng_fec_start(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct ng_fec_private *priv;
|
|
|
|
struct ng_fec_bundle *b;
|
|
|
|
struct ifnet *oifp = NULL;
|
|
|
|
struct mbuf *m0;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
priv = ifp->if_softc;
|
|
|
|
b = &priv->fec_bundle;
|
|
|
|
|
|
|
|
IF_DEQUEUE(&ifp->if_snd, m0);
|
|
|
|
if (m0 == NULL)
|
|
|
|
return;
|
|
|
|
|
2002-12-23 22:31:24 +00:00
|
|
|
BPF_MTAP(ifp, m0);
|
2002-10-29 19:12:44 +00:00
|
|
|
|
|
|
|
/* Queue up packet on the proper port. */
|
|
|
|
error = ng_fec_choose_port(b, m0, &oifp);
|
|
|
|
if (error) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
m_freem(m0);
|
|
|
|
priv->if_error = ENOBUFS;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ifp->if_opackets++;
|
|
|
|
|
2004-06-20 21:08:58 +00:00
|
|
|
priv->if_error = IF_HANDOFF(&oifp->if_snd, m0, oifp) ? 0 : ENOBUFS;
|
2003-02-26 19:49:32 +00:00
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/*
|
|
|
|
* Display an ioctl to the virtual interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
ng_fec_print_ioctl(struct ifnet *ifp, int command, caddr_t data)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
switch (command & IOC_DIRMASK) {
|
|
|
|
case IOC_VOID:
|
|
|
|
str = "IO";
|
|
|
|
break;
|
|
|
|
case IOC_OUT:
|
|
|
|
str = "IOR";
|
|
|
|
break;
|
|
|
|
case IOC_IN:
|
|
|
|
str = "IOW";
|
|
|
|
break;
|
|
|
|
case IOC_INOUT:
|
|
|
|
str = "IORW";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "IO??";
|
|
|
|
}
|
2003-10-31 18:32:15 +00:00
|
|
|
log(LOG_DEBUG, "%s: %s('%c', %d, char[%d])\n",
|
|
|
|
ifp->if_xname,
|
2002-10-29 19:12:44 +00:00
|
|
|
str,
|
|
|
|
IOCGROUP(command),
|
|
|
|
command & 0xff,
|
|
|
|
IOCPARM_LEN(command));
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
NETGRAPH NODE STUFF
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Constructor for a node
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_fec_constructor(node_p node)
|
|
|
|
{
|
|
|
|
char ifname[NG_FEC_FEC_NAME_MAX + 1];
|
|
|
|
struct ifnet *ifp;
|
|
|
|
priv_p priv;
|
2006-08-24 19:50:00 +00:00
|
|
|
const uint8_t eaddr[ETHER_ADDR_LEN] = {0, 0, 0, 0, 0, 0};
|
2002-10-29 19:12:44 +00:00
|
|
|
struct ng_fec_bundle *b;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
/* Allocate node and interface private structures */
|
2008-10-23 15:53:51 +00:00
|
|
|
priv = malloc(sizeof(*priv), M_NETGRAPH, M_NOWAIT | M_ZERO);
|
2002-10-29 19:12:44 +00:00
|
|
|
if (priv == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = priv->ifp = if_alloc(IFT_ETHER);
|
|
|
|
if (ifp == NULL) {
|
2008-10-23 15:53:51 +00:00
|
|
|
free(priv, M_NETGRAPH);
|
2005-06-10 16:49:24 +00:00
|
|
|
return (ENOSPC);
|
|
|
|
}
|
2002-10-29 19:12:44 +00:00
|
|
|
b = &priv->fec_bundle;
|
|
|
|
|
|
|
|
/* Link them together */
|
|
|
|
ifp->if_softc = priv;
|
|
|
|
|
|
|
|
/* Get an interface unit number */
|
|
|
|
if ((error = ng_fec_get_unit(&priv->unit)) != 0) {
|
2005-06-10 16:49:24 +00:00
|
|
|
if_free(ifp);
|
2008-10-23 15:53:51 +00:00
|
|
|
free(priv, M_NETGRAPH);
|
2002-10-29 19:12:44 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Link together node and private info */
|
|
|
|
NG_NODE_SET_PRIVATE(node, priv);
|
|
|
|
priv->node = node;
|
|
|
|
|
|
|
|
/* Initialize interface structure */
|
2003-10-31 18:32:15 +00:00
|
|
|
if_initname(ifp, NG_FEC_FEC_NAME, priv->unit);
|
2002-10-29 19:12:44 +00:00
|
|
|
ifp->if_start = ng_fec_start;
|
|
|
|
ifp->if_ioctl = ng_fec_ioctl;
|
|
|
|
ifp->if_init = ng_fec_init;
|
|
|
|
ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
|
|
|
|
ifp->if_mtu = NG_FEC_MTU_DEFAULT;
|
|
|
|
ifp->if_flags = (IFF_SIMPLEX|IFF_BROADCAST|IFF_MULTICAST);
|
|
|
|
ifp->if_addrlen = 0; /* XXX */
|
|
|
|
ifp->if_hdrlen = 0; /* XXX */
|
|
|
|
ifp->if_baudrate = 100000000; /* XXX */
|
2004-04-16 08:15:37 +00:00
|
|
|
TAILQ_INIT(&ifp->if_addrhead); /* XXX useless - done in if_attach */
|
2002-10-29 19:12:44 +00:00
|
|
|
|
|
|
|
/* Give this node the same name as the interface (if possible) */
|
|
|
|
bzero(ifname, sizeof(ifname));
|
2003-10-31 18:32:15 +00:00
|
|
|
strlcpy(ifname, ifp->if_xname, sizeof(ifname));
|
2002-10-29 19:12:44 +00:00
|
|
|
if (ng_name_node(node, ifname) != 0)
|
|
|
|
log(LOG_WARNING, "%s: can't acquire netgraph name\n", ifname);
|
|
|
|
|
|
|
|
/* Attach the interface */
|
2006-08-24 19:50:00 +00:00
|
|
|
ether_ifattach(ifp, eaddr);
|
2002-10-29 19:12:44 +00:00
|
|
|
callout_handle_init(&priv->fec_ch);
|
|
|
|
|
2003-02-26 19:49:32 +00:00
|
|
|
/* Override output method with our own */
|
|
|
|
ifp->if_output = ng_fec_output;
|
|
|
|
|
2002-10-29 19:12:44 +00:00
|
|
|
TAILQ_INIT(&b->ng_fec_ports);
|
|
|
|
b->fec_ifcnt = 0;
|
|
|
|
|
|
|
|
ifmedia_init(&priv->ifmedia, 0,
|
|
|
|
ng_fec_ifmedia_upd, ng_fec_ifmedia_sts);
|
|
|
|
ifmedia_add(&priv->ifmedia, IFM_ETHER|IFM_NONE, 0, NULL);
|
|
|
|
ifmedia_set(&priv->ifmedia, IFM_ETHER|IFM_NONE);
|
|
|
|
|
|
|
|
/* Done */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive a control message
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_fec_rcvmsg(node_p node, item_p item, hook_p lasthook)
|
|
|
|
{
|
|
|
|
const priv_p priv = NG_NODE_PRIVATE(node);
|
|
|
|
struct ng_fec_bundle *b;
|
|
|
|
struct ng_mesg *resp = NULL;
|
|
|
|
struct ng_mesg *msg;
|
|
|
|
char *ifname;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
NGI_GET_MSG(item, msg);
|
|
|
|
b = &priv->fec_bundle;
|
|
|
|
|
|
|
|
switch (msg->header.typecookie) {
|
|
|
|
case NGM_FEC_COOKIE:
|
|
|
|
switch (msg->header.cmd) {
|
|
|
|
case NGM_FEC_ADD_IFACE:
|
|
|
|
ifname = msg->data;
|
|
|
|
error = ng_fec_addport(priv, ifname);
|
|
|
|
break;
|
|
|
|
case NGM_FEC_DEL_IFACE:
|
|
|
|
ifname = msg->data;
|
|
|
|
error = ng_fec_delport(priv, ifname);
|
|
|
|
break;
|
|
|
|
case NGM_FEC_SET_MODE_MAC:
|
|
|
|
b->fec_btype = FEC_BTYPE_MAC;
|
|
|
|
break;
|
|
|
|
#ifdef INET
|
|
|
|
case NGM_FEC_SET_MODE_INET:
|
|
|
|
b->fec_btype = FEC_BTYPE_INET;
|
|
|
|
break;
|
|
|
|
#ifdef INET6
|
|
|
|
case NGM_FEC_SET_MODE_INET6:
|
|
|
|
b->fec_btype = FEC_BTYPE_INET6;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NG_RESPOND_MSG(error, node, item, resp);
|
|
|
|
NG_FREE_MSG(msg);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shutdown and remove the node and its associated interface.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_fec_shutdown(node_p node)
|
|
|
|
{
|
|
|
|
const priv_p priv = NG_NODE_PRIVATE(node);
|
|
|
|
struct ng_fec_bundle *b;
|
|
|
|
struct ng_fec_portlist *p;
|
|
|
|
|
|
|
|
b = &priv->fec_bundle;
|
2005-06-10 16:49:24 +00:00
|
|
|
ng_fec_stop(priv->ifp);
|
2002-10-29 19:12:44 +00:00
|
|
|
|
|
|
|
while (!TAILQ_EMPTY(&b->ng_fec_ports)) {
|
|
|
|
p = TAILQ_FIRST(&b->ng_fec_ports);
|
2007-05-18 15:05:49 +00:00
|
|
|
ng_fec_ether_cmdmulti(priv->ifp, p, 0);
|
2003-10-31 18:32:15 +00:00
|
|
|
ng_fec_delport(priv, p->fec_if->if_xname);
|
2002-10-29 19:12:44 +00:00
|
|
|
}
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ether_ifdetach(priv->ifp);
|
|
|
|
if_free_type(priv->ifp, IFT_ETHER);
|
2002-10-29 19:12:44 +00:00
|
|
|
ifmedia_removeall(&priv->ifmedia);
|
|
|
|
ng_fec_free_unit(priv->unit);
|
2008-10-23 15:53:51 +00:00
|
|
|
free(priv, M_NETGRAPH);
|
2002-10-29 19:12:44 +00:00
|
|
|
NG_NODE_SET_PRIVATE(node, NULL);
|
|
|
|
NG_NODE_UNREF(node);
|
|
|
|
return (0);
|
|
|
|
}
|
2005-02-05 08:28:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle loading and unloading for this node type.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_fec_mod_event(module_t mod, int event, void *data)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
mtx_init(&ng_fec_mtx, "ng_fec", NULL, MTX_DEF);
|
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
mtx_destroy(&ng_fec_mtx);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|