2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef _LINUX_NETDEVICE_H_
29 #define _LINUX_NETDEVICE_H_
31 #include <linux/types.h>
33 #include <sys/socket.h>
35 #include <net/if_types.h>
37 #include <net/if_var.h>
38 #include <net/if_dl.h>
40 #include <linux/completion.h>
41 #include <linux/device.h>
42 #include <linux/ethtool.h>
43 #include <linux/workqueue.h>
44 #include <linux/net.h>
45 #include <linux/notifier.h>
50 extern struct net init_net;
52 #define MAX_ADDR_LEN 20
54 #define net_device ifnet
56 #define dev_get_by_index(n, idx) ifnet_byindex_ref((idx))
57 #define dev_hold(d) if_ref((d))
58 #define dev_put(d) if_rele((d))
60 #define netif_running(dev) !!((dev)->if_drv_flags & IFF_DRV_RUNNING)
61 #define netif_oper_up(dev) !!((dev)->if_flags & IFF_UP)
62 #define netif_carrier_ok(dev) netif_running(dev)
65 netdev_priv(const struct net_device *dev)
67 return (dev->if_softc);
71 _handle_ifnet_link_event(void *arg, struct ifnet *ifp, int linkstate)
73 struct notifier_block *nb;
76 if (linkstate == LINK_STATE_UP)
77 nb->notifier_call(nb, NETDEV_UP, ifp);
79 nb->notifier_call(nb, NETDEV_DOWN, ifp);
83 _handle_ifnet_arrival_event(void *arg, struct ifnet *ifp)
85 struct notifier_block *nb;
88 nb->notifier_call(nb, NETDEV_REGISTER, ifp);
92 _handle_ifnet_departure_event(void *arg, struct ifnet *ifp)
94 struct notifier_block *nb;
97 nb->notifier_call(nb, NETDEV_UNREGISTER, ifp);
101 register_netdevice_notifier(struct notifier_block *nb)
104 nb->tags[NETDEV_UP] = EVENTHANDLER_REGISTER(
105 ifnet_link_event, _handle_ifnet_link_event, nb, 0);
106 nb->tags[NETDEV_REGISTER] = EVENTHANDLER_REGISTER(
107 ifnet_arrival_event, _handle_ifnet_arrival_event, nb, 0);
108 nb->tags[NETDEV_UNREGISTER] = EVENTHANDLER_REGISTER(
109 ifnet_departure_event, _handle_ifnet_departure_event, nb, 0);
114 unregister_netdevice_notifier(struct notifier_block *nb)
117 EVENTHANDLER_DEREGISTER(ifnet_link_event, nb->tags[NETDEV_UP]);
118 EVENTHANDLER_DEREGISTER(ifnet_arrival_event, nb->tags[NETDEV_REGISTER]);
119 EVENTHANDLER_DEREGISTER(ifnet_departure_event,
120 nb->tags[NETDEV_UNREGISTER]);
125 #define rtnl_unlock()
128 dev_mc_delete(struct net_device *dev, void *addr, int alen, int all)
130 struct sockaddr_dl sdl;
132 if (alen > sizeof(sdl.sdl_data))
134 memset(&sdl, 0, sizeof(sdl));
135 sdl.sdl_len = sizeof(sdl);
136 sdl.sdl_family = AF_LINK;
138 memcpy(&sdl.sdl_data, addr, alen);
140 return -if_delmulti(dev, (struct sockaddr *)&sdl);
144 dev_mc_add(struct net_device *dev, void *addr, int alen, int newonly)
146 struct sockaddr_dl sdl;
148 if (alen > sizeof(sdl.sdl_data))
150 memset(&sdl, 0, sizeof(sdl));
151 sdl.sdl_len = sizeof(sdl);
152 sdl.sdl_family = AF_LINK;
154 memcpy(&sdl.sdl_data, addr, alen);
156 return -if_addmulti(dev, (struct sockaddr *)&sdl, NULL);
159 #endif /* _LINUX_NETDEVICE_H_ */