2 * Copyright (c) 1980, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)if.c 8.3 (Berkeley) 1/4/94
34 * $FreeBSD: src/sys/net/if.c,v 1.185 2004/03/13 02:35:03 brooks Exp $
35 * $DragonFly: src/sys/net/if.c,v 1.43 2005/11/28 17:13:45 dillon Exp $
38 #include "opt_compat.h"
39 #include "opt_inet6.h"
41 #include "opt_polling.h"
43 #include <sys/param.h>
44 #include <sys/malloc.h>
46 #include <sys/systm.h>
48 #include <sys/protosw.h>
49 #include <sys/socket.h>
50 #include <sys/socketvar.h>
51 #include <sys/socketops.h>
52 #include <sys/protosw.h>
53 #include <sys/kernel.h>
54 #include <sys/sockio.h>
55 #include <sys/syslog.h>
56 #include <sys/sysctl.h>
57 #include <sys/domain.h>
58 #include <sys/thread.h>
59 #include <sys/serialize.h>
62 #include <net/if_arp.h>
63 #include <net/if_dl.h>
64 #include <net/if_types.h>
65 #include <net/if_var.h>
66 #include <net/ifq_var.h>
67 #include <net/radix.h>
68 #include <net/route.h>
69 #include <machine/stdarg.h>
71 #include <sys/thread2.h>
73 #if defined(INET) || defined(INET6)
75 #include <netinet/in.h>
76 #include <netinet/in_var.h>
77 #include <netinet/if_ether.h>
79 #include <machine/clock.h> /* XXX: temporal workaround for fxp issue */
80 #include <netinet6/in6_var.h>
81 #include <netinet6/in6_ifattach.h>
85 #if defined(COMPAT_43)
86 #include <emulation/43bsd/43bsd_socket.h>
87 #endif /* COMPAT_43 */
90 * Support for non-ALTQ interfaces.
92 static int ifq_classic_enqueue(struct ifaltq *, struct mbuf *,
93 struct altq_pktattr *);
95 ifq_classic_dequeue(struct ifaltq *, struct mbuf *, int);
96 static int ifq_classic_request(struct ifaltq *, int, void *);
99 * System initialization
102 static void if_attachdomain(void *);
103 static void if_attachdomain1(struct ifnet *);
104 static int ifconf (u_long, caddr_t, struct thread *);
105 static void ifinit (void *);
106 static void if_slowtimo (void *);
107 static void link_rtrequest (int, struct rtentry *, struct rt_addrinfo *);
108 static int if_rtdel (struct radix_node *, void *);
110 SYSINIT(interfaces, SI_SUB_PROTO_IF, SI_ORDER_FIRST, ifinit, NULL)
112 MALLOC_DEFINE(M_IFADDR, "ifaddr", "interface address");
113 MALLOC_DEFINE(M_IFMADDR, "ether_multi", "link-level multicast address");
114 MALLOC_DEFINE(M_CLONE, "clone", "interface cloning framework");
116 int ifqmaxlen = IFQ_MAXLEN;
117 struct ifnethead ifnet; /* depend on static init XXX */
121 * XXX: declare here to avoid to include many inet6 related files..
122 * should be more generalized?
124 extern void nd6_setmtu (struct ifnet *);
127 struct if_clone *if_clone_lookup (const char *, int *);
128 int if_clone_list (struct if_clonereq *);
130 LIST_HEAD(, if_clone) if_cloners = LIST_HEAD_INITIALIZER(if_cloners);
131 int if_cloners_count;
133 struct callout if_slowtimo_timer;
136 * Network interface utility routines.
138 * Routines with ifa_ifwith* names take sockaddr *'s as
147 callout_init(&if_slowtimo_timer);
150 TAILQ_FOREACH(ifp, &ifnet, if_link) {
151 if (ifp->if_snd.ifq_maxlen == 0) {
152 if_printf(ifp, "XXX: driver didn't set ifq_maxlen\n");
153 ifp->if_snd.ifq_maxlen = ifqmaxlen;
162 struct ifnet **ifindex2ifnet = NULL;
165 * Attach an interface to the list of "active" interfaces.
167 * The serializer is optional. If non-NULL access to the interface
171 if_attach(struct ifnet *ifp, lwkt_serialize_t serializer)
173 unsigned socksize, ifasize;
174 int namelen, masklen;
175 struct sockaddr_dl *sdl;
179 static int if_indexlim = 8;
180 static boolean_t inited;
188 * The serializer can be passed in from the device, allowing the
189 * same serializer to be used for both the interrupt interlock and
190 * the device queue. If not specified, the netif structure will
191 * use an embedded serializer.
193 if (serializer == NULL) {
194 serializer = &ifp->if_default_serializer;
195 lwkt_serialize_init(serializer);
197 ifp->if_serializer = serializer;
199 TAILQ_INSERT_TAIL(&ifnet, ifp, if_link);
200 ifp->if_index = ++if_index;
203 * The old code would work if the interface passed a pre-existing
204 * chain of ifaddrs to this code. We don't trust our callers to
205 * properly initialize the tailq, however, so we no longer allow
206 * this unlikely case.
208 TAILQ_INIT(&ifp->if_addrhead);
209 TAILQ_INIT(&ifp->if_prefixhead);
210 LIST_INIT(&ifp->if_multiaddrs);
211 getmicrotime(&ifp->if_lastchange);
212 if (ifindex2ifnet == NULL || if_index >= if_indexlim) {
218 /* grow ifindex2ifnet */
219 n = if_indexlim * sizeof(*q);
220 q = malloc(n, M_IFADDR, M_WAITOK | M_ZERO);
222 bcopy(ifindex2ifnet, q, n/2);
223 free(ifindex2ifnet, M_IFADDR);
228 ifindex2ifnet[if_index] = ifp;
231 * create a Link Level name for this device
233 namelen = strlen(ifp->if_xname);
234 #define _offsetof(t, m) ((int)((caddr_t)&((t *)0)->m))
235 masklen = _offsetof(struct sockaddr_dl, sdl_data[0]) + namelen;
236 socksize = masklen + ifp->if_addrlen;
237 #define ROUNDUP(a) (1 + (((a) - 1) | (sizeof(long) - 1)))
238 if (socksize < sizeof(*sdl))
239 socksize = sizeof(*sdl);
240 socksize = ROUNDUP(socksize);
241 ifasize = sizeof(struct ifaddr) + 2 * socksize;
242 ifa = malloc(ifasize, M_IFADDR, M_WAITOK | M_ZERO);
243 sdl = (struct sockaddr_dl *)(ifa + 1);
244 sdl->sdl_len = socksize;
245 sdl->sdl_family = AF_LINK;
246 bcopy(ifp->if_xname, sdl->sdl_data, namelen);
247 sdl->sdl_nlen = namelen;
248 sdl->sdl_index = ifp->if_index;
249 sdl->sdl_type = ifp->if_type;
250 ifp->if_lladdr = ifa;
252 ifa->ifa_rtrequest = link_rtrequest;
253 ifa->ifa_addr = (struct sockaddr *)sdl;
254 sdl = (struct sockaddr_dl *)(socksize + (caddr_t)sdl);
255 ifa->ifa_netmask = (struct sockaddr *)sdl;
256 sdl->sdl_len = masklen;
258 sdl->sdl_data[--namelen] = 0xff;
259 TAILQ_INSERT_HEAD(&ifp->if_addrhead, ifa, ifa_link);
261 EVENTHANDLER_INVOKE(ifnet_attach_event, ifp);
265 ifq->altq_disc = NULL;
266 ifq->altq_flags &= ALTQF_CANTCHANGE;
267 ifq->altq_tbr = NULL;
269 ifq_set_classic(ifq);
271 if (!SLIST_EMPTY(&domains))
272 if_attachdomain1(ifp);
274 /* Announce the interface. */
275 rt_ifannouncemsg(ifp, IFAN_ARRIVAL);
279 if_attachdomain(void *dummy)
284 TAILQ_FOREACH(ifp, &ifnet, if_list)
285 if_attachdomain1(ifp);
288 SYSINIT(domainifattach, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_FIRST,
289 if_attachdomain, NULL);
292 if_attachdomain1(struct ifnet *ifp)
298 /* address family dependent data region */
299 bzero(ifp->if_afdata, sizeof(ifp->if_afdata));
300 SLIST_FOREACH(dp, &domains, dom_next)
301 if (dp->dom_ifattach)
302 ifp->if_afdata[dp->dom_family] =
303 (*dp->dom_ifattach)(ifp);
308 * Detach an interface, removing it from the
309 * list of "active" interfaces.
312 if_detach(struct ifnet *ifp)
315 struct radix_node_head *rnh;
319 EVENTHANDLER_INVOKE(ifnet_detach_event, ifp);
322 * Remove routes and flush queues.
325 #ifdef DEVICE_POLLING
326 if (ifp->if_flags & IFF_POLLING)
327 ether_poll_deregister(ifp);
331 if (ifq_is_enabled(&ifp->if_snd))
332 altq_disable(&ifp->if_snd);
333 if (ifq_is_attached(&ifp->if_snd))
334 altq_detach(&ifp->if_snd);
337 * Clean up all addresses.
339 ifp->if_lladdr = NULL;
341 for (ifa = TAILQ_FIRST(&ifp->if_addrhead); ifa;
342 ifa = TAILQ_FIRST(&ifp->if_addrhead)) {
344 /* XXX: Ugly!! ad hoc just for INET */
345 if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) {
346 struct ifaliasreq ifr;
348 bzero(&ifr, sizeof ifr);
349 ifr.ifra_addr = *ifa->ifa_addr;
350 if (ifa->ifa_dstaddr)
351 ifr.ifra_broadaddr = *ifa->ifa_dstaddr;
352 if (in_control(NULL, SIOCDIFADDR, (caddr_t)&ifr, ifp,
358 if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET6) {
360 /* ifp_addrhead is already updated */
364 TAILQ_REMOVE(&ifp->if_addrhead, ifa, ifa_link);
370 * Remove all IPv4 kernel structures related to ifp.
377 * Remove all IPv6 kernel structs related to ifp. This should be done
378 * before removing routing entries below, since IPv6 interface direct
379 * routes are expected to be removed by the IPv6-specific kernel API.
380 * Otherwise, the kernel will detect some inconsistency and bark it.
386 * Delete all remaining routes using this interface
387 * Unfortuneatly the only way to do this is to slog through
388 * the entire routing table looking for routes which point
389 * to this interface...oh well...
391 for (i = 1; i <= AF_MAX; i++) {
392 if ((rnh = rt_tables[i]) == NULL)
394 rnh->rnh_walktree(rnh, if_rtdel, ifp);
397 /* Announce that the interface is gone. */
398 rt_ifannouncemsg(ifp, IFAN_DEPARTURE);
400 SLIST_FOREACH(dp, &domains, dom_next)
401 if (dp->dom_ifdetach && ifp->if_afdata[dp->dom_family])
402 (*dp->dom_ifdetach)(ifp,
403 ifp->if_afdata[dp->dom_family]);
406 * Remove interface from ifindex2ifp[] and maybe decrement if_index.
408 ifindex2ifnet[ifp->if_index] = NULL;
409 while (if_index > 0 && ifindex2ifnet[if_index] == NULL)
412 TAILQ_REMOVE(&ifnet, ifp, if_link);
417 * Delete Routes for a Network Interface
419 * Called for each routing entry via the rnh->rnh_walktree() call above
420 * to delete all route entries referencing a detaching network interface.
423 * rn pointer to node in the routing table
424 * arg argument passed to rnh->rnh_walktree() - detaching interface
428 * errno failed - reason indicated
432 if_rtdel(struct radix_node *rn, void *arg)
434 struct rtentry *rt = (struct rtentry *)rn;
435 struct ifnet *ifp = arg;
438 if (rt->rt_ifp == ifp) {
441 * Protect (sorta) against walktree recursion problems
444 if (!(rt->rt_flags & RTF_UP))
447 err = rtrequest(RTM_DELETE, rt_key(rt), rt->rt_gateway,
448 rt_mask(rt), rt->rt_flags,
449 (struct rtentry **) NULL);
451 log(LOG_WARNING, "if_rtdel: error %d\n", err);
459 * Create a clone network interface.
462 if_clone_create(char *name, int len)
464 struct if_clone *ifc;
466 int wildcard, bytoff, bitoff;
470 ifc = if_clone_lookup(name, &unit);
474 if (ifunit(name) != NULL)
478 wildcard = (unit < 0);
480 * Find a free unit if none was given.
483 while (bytoff < ifc->ifc_bmlen &&
484 ifc->ifc_units[bytoff] == 0xff)
486 if (bytoff >= ifc->ifc_bmlen)
488 while ((ifc->ifc_units[bytoff] & (1 << bitoff)) != 0)
490 unit = (bytoff << 3) + bitoff;
493 if (unit > ifc->ifc_maxunit)
496 err = (*ifc->ifc_create)(ifc, unit);
502 bitoff = unit - (bytoff << 3);
506 * Allocate the unit in the bitmap.
508 KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) == 0,
509 ("%s: bit is already set", __func__));
510 ifc->ifc_units[bytoff] |= (1 << bitoff);
512 /* In the wildcard case, we need to update the name. */
514 for (dp = name; *dp != '\0'; dp++);
515 if (snprintf(dp, len - (dp-name), "%d", unit) >
516 len - (dp-name) - 1) {
518 * This can only be a programmer error and
519 * there's no straightforward way to recover if
522 panic("if_clone_create(): interface name too long");
527 EVENTHANDLER_INVOKE(if_clone_event, ifc);
533 * Destroy a clone network interface.
536 if_clone_destroy(const char *name)
538 struct if_clone *ifc;
543 ifc = if_clone_lookup(name, &unit);
547 if (unit < ifc->ifc_minifs)
554 if (ifc->ifc_destroy == NULL)
557 (*ifc->ifc_destroy)(ifp);
560 * Compute offset in the bitmap and deallocate the unit.
563 bitoff = unit - (bytoff << 3);
564 KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) != 0,
565 ("%s: bit is already cleared", __func__));
566 ifc->ifc_units[bytoff] &= ~(1 << bitoff);
571 * Look up a network interface cloner.
574 if_clone_lookup(const char *name, int *unitp)
576 struct if_clone *ifc;
580 for (ifc = LIST_FIRST(&if_cloners); ifc != NULL;) {
581 for (cp = name, i = 0; i < ifc->ifc_namelen; i++, cp++) {
582 if (ifc->ifc_name[i] != *cp)
587 ifc = LIST_NEXT(ifc, ifc_list);
591 return ((struct if_clone *)NULL);
597 for (i = 0; *cp != '\0'; cp++) {
598 if (*cp < '0' || *cp > '9') {
599 /* Bogus unit number. */
602 i = (i * 10) + (*cp - '0');
612 * Register a network interface cloner.
615 if_clone_attach(struct if_clone *ifc)
622 KASSERT(ifc->ifc_minifs - 1 <= ifc->ifc_maxunit,
623 ("%s: %s requested more units then allowed (%d > %d)",
624 __func__, ifc->ifc_name, ifc->ifc_minifs,
625 ifc->ifc_maxunit + 1));
627 * Compute bitmap size and allocate it.
629 maxclone = ifc->ifc_maxunit + 1;
631 if ((len << 3) < maxclone)
633 ifc->ifc_units = malloc(len, M_CLONE, M_WAITOK | M_ZERO);
634 ifc->ifc_bmlen = len;
636 LIST_INSERT_HEAD(&if_cloners, ifc, ifc_list);
639 for (unit = 0; unit < ifc->ifc_minifs; unit++) {
640 err = (*ifc->ifc_create)(ifc, unit);
642 ("%s: failed to create required interface %s%d",
643 __func__, ifc->ifc_name, unit));
645 /* Allocate the unit in the bitmap. */
647 bitoff = unit - (bytoff << 3);
648 ifc->ifc_units[bytoff] |= (1 << bitoff);
653 * Unregister a network interface cloner.
656 if_clone_detach(struct if_clone *ifc)
659 LIST_REMOVE(ifc, ifc_list);
660 free(ifc->ifc_units, M_CLONE);
665 * Provide list of interface cloners to userspace.
668 if_clone_list(struct if_clonereq *ifcr)
670 char outbuf[IFNAMSIZ], *dst;
671 struct if_clone *ifc;
672 int count, error = 0;
674 ifcr->ifcr_total = if_cloners_count;
675 if ((dst = ifcr->ifcr_buffer) == NULL) {
676 /* Just asking how many there are. */
680 if (ifcr->ifcr_count < 0)
683 count = (if_cloners_count < ifcr->ifcr_count) ?
684 if_cloners_count : ifcr->ifcr_count;
686 for (ifc = LIST_FIRST(&if_cloners); ifc != NULL && count != 0;
687 ifc = LIST_NEXT(ifc, ifc_list), count--, dst += IFNAMSIZ) {
688 strlcpy(outbuf, ifc->ifc_name, IFNAMSIZ);
689 error = copyout(outbuf, dst, IFNAMSIZ);
698 * Locate an interface based on a complete address.
701 ifa_ifwithaddr(struct sockaddr *addr)
706 TAILQ_FOREACH(ifp, &ifnet, if_link)
707 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
708 if (ifa->ifa_addr->sa_family != addr->sa_family)
710 if (sa_equal(addr, ifa->ifa_addr))
712 if ((ifp->if_flags & IFF_BROADCAST) && ifa->ifa_broadaddr &&
713 /* IPv6 doesn't have broadcast */
714 ifa->ifa_broadaddr->sa_len != 0 &&
715 sa_equal(ifa->ifa_broadaddr, addr))
718 return ((struct ifaddr *)NULL);
721 * Locate the point to point interface with a given destination address.
724 ifa_ifwithdstaddr(struct sockaddr *addr)
729 TAILQ_FOREACH(ifp, &ifnet, if_link)
730 if (ifp->if_flags & IFF_POINTOPOINT)
731 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
732 if (ifa->ifa_addr->sa_family != addr->sa_family)
734 if (ifa->ifa_dstaddr &&
735 sa_equal(addr, ifa->ifa_dstaddr))
738 return ((struct ifaddr *)NULL);
742 * Find an interface on a specific network. If many, choice
743 * is most specific found.
746 ifa_ifwithnet(struct sockaddr *addr)
750 struct ifaddr *ifa_maybe = (struct ifaddr *) 0;
751 u_int af = addr->sa_family;
752 char *addr_data = addr->sa_data, *cplim;
755 * AF_LINK addresses can be looked up directly by their index number,
756 * so do that if we can.
759 struct sockaddr_dl *sdl = (struct sockaddr_dl *)addr;
761 if (sdl->sdl_index && sdl->sdl_index <= if_index)
762 return (ifindex2ifnet[sdl->sdl_index]->if_lladdr);
766 * Scan though each interface, looking for ones that have
767 * addresses in this address family.
769 TAILQ_FOREACH(ifp, &ifnet, if_link) {
770 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
771 char *cp, *cp2, *cp3;
773 if (ifa->ifa_addr->sa_family != af)
775 if (af == AF_INET && ifp->if_flags & IFF_POINTOPOINT) {
777 * This is a bit broken as it doesn't
778 * take into account that the remote end may
779 * be a single node in the network we are
781 * The trouble is that we don't know the
782 * netmask for the remote end.
784 if (ifa->ifa_dstaddr != NULL &&
785 sa_equal(addr, ifa->ifa_dstaddr))
789 * if we have a special address handler,
790 * then use it instead of the generic one.
792 if (ifa->ifa_claim_addr) {
793 if ((*ifa->ifa_claim_addr)(ifa, addr)) {
801 * Scan all the bits in the ifa's address.
802 * If a bit dissagrees with what we are
803 * looking for, mask it with the netmask
804 * to see if it really matters.
807 if (ifa->ifa_netmask == 0)
810 cp2 = ifa->ifa_addr->sa_data;
811 cp3 = ifa->ifa_netmask->sa_data;
812 cplim = ifa->ifa_netmask->sa_len +
813 (char *)ifa->ifa_netmask;
815 if ((*cp++ ^ *cp2++) & *cp3++)
816 goto next; /* next address! */
818 * If the netmask of what we just found
819 * is more specific than what we had before
820 * (if we had one) then remember the new one
821 * before continuing to search
822 * for an even better one.
824 if (ifa_maybe == 0 ||
825 rn_refines((char *)ifa->ifa_netmask,
826 (char *)ifa_maybe->ifa_netmask))
835 * Find an interface address specific to an interface best matching
839 ifaof_ifpforaddr(struct sockaddr *addr, struct ifnet *ifp)
842 char *cp, *cp2, *cp3;
844 struct ifaddr *ifa_maybe = 0;
845 u_int af = addr->sa_family;
849 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
850 if (ifa->ifa_addr->sa_family != af)
854 if (ifa->ifa_netmask == NULL) {
855 if (sa_equal(addr, ifa->ifa_addr) ||
856 (ifa->ifa_dstaddr != NULL &&
857 sa_equal(addr, ifa->ifa_dstaddr)))
861 if (ifp->if_flags & IFF_POINTOPOINT) {
862 if (sa_equal(addr, ifa->ifa_dstaddr))
866 cp2 = ifa->ifa_addr->sa_data;
867 cp3 = ifa->ifa_netmask->sa_data;
868 cplim = ifa->ifa_netmask->sa_len + (char *)ifa->ifa_netmask;
869 for (; cp3 < cplim; cp3++)
870 if ((*cp++ ^ *cp2++) & *cp3)
879 #include <net/route.h>
882 * Default action when installing a route with a Link Level gateway.
883 * Lookup an appropriate real ifa to point to.
884 * This should be moved to /sys/net/link.c eventually.
887 link_rtrequest(int cmd, struct rtentry *rt, struct rt_addrinfo *info)
890 struct sockaddr *dst;
893 if (cmd != RTM_ADD || (ifa = rt->rt_ifa) == NULL ||
894 (ifp = ifa->ifa_ifp) == NULL || (dst = rt_key(rt)) == NULL)
896 ifa = ifaof_ifpforaddr(dst, ifp);
901 if (ifa->ifa_rtrequest && ifa->ifa_rtrequest != link_rtrequest)
902 ifa->ifa_rtrequest(cmd, rt, info);
907 * Mark an interface down and notify protocols of
909 * NOTE: must be called at splnet or eqivalent.
912 if_unroute(struct ifnet *ifp, int flag, int fam)
916 ifp->if_flags &= ~flag;
917 getmicrotime(&ifp->if_lastchange);
918 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
919 if (fam == PF_UNSPEC || (fam == ifa->ifa_addr->sa_family))
920 pfctlinput(PRC_IFDOWN, ifa->ifa_addr);
921 ifq_purge(&ifp->if_snd);
926 * Mark an interface up and notify protocols of
928 * NOTE: must be called at splnet or eqivalent.
931 if_route(struct ifnet *ifp, int flag, int fam)
935 ifp->if_flags |= flag;
936 getmicrotime(&ifp->if_lastchange);
937 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
938 if (fam == PF_UNSPEC || (fam == ifa->ifa_addr->sa_family))
939 pfctlinput(PRC_IFUP, ifa->ifa_addr);
947 * Mark an interface down and notify protocols of the transition. An
948 * interface going down is also considered to be a synchronizing event.
949 * We must ensure that all packet processing related to the interface
950 * has completed before we return so e.g. the caller can free the ifnet
951 * structure that the mbufs may be referencing.
953 * NOTE: must be called at splnet or eqivalent.
956 if_down(struct ifnet *ifp)
958 if_unroute(ifp, IFF_UP, AF_UNSPEC);
959 netmsg_service_sync();
963 * Mark an interface up and notify protocols of
965 * NOTE: must be called at splnet or eqivalent.
968 if_up(struct ifnet *ifp)
971 if_route(ifp, IFF_UP, AF_UNSPEC);
975 * Handle interface watchdog timer routines. Called
976 * from softclock, we decrement timers (if set) and
977 * call the appropriate interface routine on expiration.
980 if_slowtimo(void *arg)
986 TAILQ_FOREACH(ifp, &ifnet, if_link) {
987 if (ifp->if_timer == 0 || --ifp->if_timer)
989 if (ifp->if_watchdog) {
990 if (lwkt_serialize_try(ifp->if_serializer)) {
991 (*ifp->if_watchdog)(ifp);
992 lwkt_serialize_exit(ifp->if_serializer);
994 /* try again next timeout */
1002 callout_reset(&if_slowtimo_timer, hz / IFNET_SLOWHZ, if_slowtimo, NULL);
1006 * Map interface name to
1007 * interface structure pointer.
1010 ifunit(const char *name)
1015 * Search all the interfaces for this name/number
1018 TAILQ_FOREACH(ifp, &ifnet, if_link) {
1019 if (strncmp(ifp->if_xname, name, IFNAMSIZ) == 0)
1027 * Map interface name in a sockaddr_dl to
1028 * interface structure pointer.
1031 if_withname(struct sockaddr *sa)
1033 char ifname[IFNAMSIZ+1];
1034 struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa;
1036 if ( (sa->sa_family != AF_LINK) || (sdl->sdl_nlen == 0) ||
1037 (sdl->sdl_nlen > IFNAMSIZ) )
1041 * ifunit wants a null-terminated name. It may not be null-terminated
1042 * in the sockaddr. We don't want to change the caller's sockaddr,
1043 * and there might not be room to put the trailing null anyway, so we
1044 * make a local copy that we know we can null terminate safely.
1047 bcopy(sdl->sdl_data, ifname, sdl->sdl_nlen);
1048 ifname[sdl->sdl_nlen] = '\0';
1049 return ifunit(ifname);
1057 ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td)
1065 size_t namelen, onamelen;
1066 char new_name[IFNAMSIZ];
1068 struct sockaddr_dl *sdl;
1074 return (ifconf(cmd, data, td));
1076 ifr = (struct ifreq *)data;
1081 if ((error = suser(td)) != 0)
1083 return ((cmd == SIOCIFCREATE) ?
1084 if_clone_create(ifr->ifr_name, sizeof(ifr->ifr_name)) :
1085 if_clone_destroy(ifr->ifr_name));
1087 case SIOCIFGCLONERS:
1088 return (if_clone_list((struct if_clonereq *)data));
1091 ifp = ifunit(ifr->ifr_name);
1097 ifr->ifr_flags = ifp->if_flags;
1098 ifr->ifr_flagshigh = ifp->if_flags >> 16;
1102 ifr->ifr_reqcap = ifp->if_capabilities;
1103 ifr->ifr_curcap = ifp->if_capenable;
1107 ifr->ifr_metric = ifp->if_metric;
1111 ifr->ifr_mtu = ifp->if_mtu;
1115 ifr->ifr_phys = ifp->if_physical;
1122 new_flags = (ifr->ifr_flags & 0xffff) |
1123 (ifr->ifr_flagshigh << 16);
1124 if (ifp->if_flags & IFF_SMART) {
1125 /* Smart drivers twiddle their own routes */
1126 } else if (ifp->if_flags & IFF_UP &&
1127 (new_flags & IFF_UP) == 0) {
1131 } else if (new_flags & IFF_UP &&
1132 (ifp->if_flags & IFF_UP) == 0) {
1138 #ifdef DEVICE_POLLING
1139 if ((new_flags ^ ifp->if_flags) & IFF_POLLING) {
1140 if (new_flags & IFF_POLLING) {
1141 ether_poll_register(ifp);
1143 ether_poll_deregister(ifp);
1148 ifp->if_flags = (ifp->if_flags & IFF_CANTCHANGE) |
1149 (new_flags &~ IFF_CANTCHANGE);
1150 if (new_flags & IFF_PPROMISC) {
1151 /* Permanently promiscuous mode requested */
1152 ifp->if_flags |= IFF_PROMISC;
1153 } else if (ifp->if_pcount == 0) {
1154 ifp->if_flags &= ~IFF_PROMISC;
1156 if (ifp->if_ioctl) {
1157 lwkt_serialize_enter(ifp->if_serializer);
1158 ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred);
1159 lwkt_serialize_exit(ifp->if_serializer);
1161 getmicrotime(&ifp->if_lastchange);
1168 if (ifr->ifr_reqcap & ~ifp->if_capabilities)
1170 lwkt_serialize_enter(ifp->if_serializer);
1171 ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred);
1172 lwkt_serialize_exit(ifp->if_serializer);
1179 error = copyinstr(ifr->ifr_data, new_name, IFNAMSIZ, NULL);
1182 if (new_name[0] == '\0')
1184 if (ifunit(new_name) != NULL)
1187 EVENTHANDLER_INVOKE(ifnet_detach_event, ifp);
1189 /* Announce the departure of the interface. */
1190 rt_ifannouncemsg(ifp, IFAN_DEPARTURE);
1192 strlcpy(ifp->if_xname, new_name, sizeof(ifp->if_xname));
1193 ifa = TAILQ_FIRST(&ifp->if_addrhead);
1194 /* XXX IFA_LOCK(ifa); */
1195 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
1196 namelen = strlen(new_name);
1197 onamelen = sdl->sdl_nlen;
1199 * Move the address if needed. This is safe because we
1200 * allocate space for a name of length IFNAMSIZ when we
1201 * create this in if_attach().
1203 if (namelen != onamelen) {
1204 bcopy(sdl->sdl_data + onamelen,
1205 sdl->sdl_data + namelen, sdl->sdl_alen);
1207 bcopy(new_name, sdl->sdl_data, namelen);
1208 sdl->sdl_nlen = namelen;
1209 sdl = (struct sockaddr_dl *)ifa->ifa_netmask;
1210 bzero(sdl->sdl_data, onamelen);
1211 while (namelen != 0)
1212 sdl->sdl_data[--namelen] = 0xff;
1213 /* XXX IFA_UNLOCK(ifa) */
1215 EVENTHANDLER_INVOKE(ifnet_attach_event, ifp);
1217 /* Announce the return of the interface. */
1218 rt_ifannouncemsg(ifp, IFAN_ARRIVAL);
1225 ifp->if_metric = ifr->ifr_metric;
1226 getmicrotime(&ifp->if_lastchange);
1235 lwkt_serialize_enter(ifp->if_serializer);
1236 error = ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred);
1237 lwkt_serialize_exit(ifp->if_serializer);
1239 getmicrotime(&ifp->if_lastchange);
1244 u_long oldmtu = ifp->if_mtu;
1249 if (ifp->if_ioctl == NULL)
1250 return (EOPNOTSUPP);
1251 if (ifr->ifr_mtu < IF_MINMTU || ifr->ifr_mtu > IF_MAXMTU)
1253 lwkt_serialize_enter(ifp->if_serializer);
1254 error = ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred);
1255 lwkt_serialize_exit(ifp->if_serializer);
1257 getmicrotime(&ifp->if_lastchange);
1261 * If the link MTU changed, do network layer specific procedure.
1263 if (ifp->if_mtu != oldmtu) {
1277 /* Don't allow group membership on non-multicast interfaces. */
1278 if ((ifp->if_flags & IFF_MULTICAST) == 0)
1281 /* Don't let users screw up protocols' entries. */
1282 if (ifr->ifr_addr.sa_family != AF_LINK)
1285 if (cmd == SIOCADDMULTI) {
1286 struct ifmultiaddr *ifma;
1287 error = if_addmulti(ifp, &ifr->ifr_addr, &ifma);
1289 error = if_delmulti(ifp, &ifr->ifr_addr);
1292 getmicrotime(&ifp->if_lastchange);
1295 case SIOCSIFPHYADDR:
1296 case SIOCDIFPHYADDR:
1298 case SIOCSIFPHYADDR_IN6:
1300 case SIOCSLIFPHYADDR:
1302 case SIOCSIFGENERIC:
1306 if (ifp->if_ioctl == 0)
1307 return (EOPNOTSUPP);
1308 lwkt_serialize_enter(ifp->if_serializer);
1309 error = ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred);
1310 lwkt_serialize_exit(ifp->if_serializer);
1312 getmicrotime(&ifp->if_lastchange);
1316 ifs = (struct ifstat *)data;
1317 ifs->ascii[0] = '\0';
1319 case SIOCGIFPSRCADDR:
1320 case SIOCGIFPDSTADDR:
1321 case SIOCGLIFPHYADDR:
1323 case SIOCGIFGENERIC:
1324 if (ifp->if_ioctl == NULL)
1325 return (EOPNOTSUPP);
1326 lwkt_serialize_enter(ifp->if_serializer);
1327 error = ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred);
1328 lwkt_serialize_exit(ifp->if_serializer);
1335 return if_setlladdr(ifp,
1336 ifr->ifr_addr.sa_data, ifr->ifr_addr.sa_len);
1339 oif_flags = ifp->if_flags;
1340 if (so->so_proto == 0)
1341 return (EOPNOTSUPP);
1343 error = so_pru_control(so, cmd, data, ifp, td);
1350 case SIOCSIFDSTADDR:
1352 case SIOCSIFBRDADDR:
1353 case SIOCSIFNETMASK:
1354 #if BYTE_ORDER != BIG_ENDIAN
1355 if (ifr->ifr_addr.sa_family == 0 &&
1356 ifr->ifr_addr.sa_len < 16) {
1357 ifr->ifr_addr.sa_family = ifr->ifr_addr.sa_len;
1358 ifr->ifr_addr.sa_len = 16;
1361 if (ifr->ifr_addr.sa_len == 0)
1362 ifr->ifr_addr.sa_len = 16;
1370 case OSIOCGIFDSTADDR:
1371 cmd = SIOCGIFDSTADDR;
1374 case OSIOCGIFBRDADDR:
1375 cmd = SIOCGIFBRDADDR;
1378 case OSIOCGIFNETMASK:
1379 cmd = SIOCGIFNETMASK;
1381 error = so_pru_control(so, cmd, data, ifp, td);
1385 case OSIOCGIFDSTADDR:
1386 case OSIOCGIFBRDADDR:
1387 case OSIOCGIFNETMASK:
1388 *(u_short *)&ifr->ifr_addr = ifr->ifr_addr.sa_family;
1392 #endif /* COMPAT_43 */
1394 if ((oif_flags ^ ifp->if_flags) & IFF_UP) {
1396 DELAY(100);/* XXX: temporary workaround for fxp issue*/
1397 if (ifp->if_flags & IFF_UP) {
1411 * Set/clear promiscuous mode on interface ifp based on the truth value
1412 * of pswitch. The calls are reference counted so that only the first
1413 * "on" request actually has an effect, as does the final "off" request.
1414 * Results are undefined if the "off" and "on" requests are not matched.
1417 ifpromisc(struct ifnet *ifp, int pswitch)
1423 oldflags = ifp->if_flags;
1424 if (ifp->if_flags & IFF_PPROMISC) {
1425 /* Do nothing if device is in permanently promiscuous mode */
1426 ifp->if_pcount += pswitch ? 1 : -1;
1431 * If the device is not configured up, we cannot put it in
1434 if ((ifp->if_flags & IFF_UP) == 0)
1436 if (ifp->if_pcount++ != 0)
1438 ifp->if_flags |= IFF_PROMISC;
1439 log(LOG_INFO, "%s: promiscuous mode enabled\n",
1442 if (--ifp->if_pcount > 0)
1444 ifp->if_flags &= ~IFF_PROMISC;
1445 log(LOG_INFO, "%s: promiscuous mode disabled\n",
1448 ifr.ifr_flags = ifp->if_flags;
1449 ifr.ifr_flagshigh = ifp->if_flags >> 16;
1450 lwkt_serialize_enter(ifp->if_serializer);
1451 error = ifp->if_ioctl(ifp, SIOCSIFFLAGS, (caddr_t)&ifr,
1452 (struct ucred *)NULL);
1453 lwkt_serialize_exit(ifp->if_serializer);
1457 ifp->if_flags = oldflags;
1462 * Return interface configuration
1463 * of system. List may be used
1464 * in later ioctl's (above) to get
1465 * other information.
1468 ifconf(u_long cmd, caddr_t data, struct thread *td)
1470 struct ifconf *ifc = (struct ifconf *)data;
1473 struct sockaddr *sa;
1474 struct ifreq ifr, *ifrp;
1475 int space = ifc->ifc_len, error = 0;
1477 ifrp = ifc->ifc_req;
1478 TAILQ_FOREACH(ifp, &ifnet, if_link) {
1481 if (space <= sizeof ifr)
1485 * Zero the stack declared structure first to prevent
1486 * memory disclosure.
1488 bzero(&ifr, sizeof(ifr));
1489 if (strlcpy(ifr.ifr_name, ifp->if_xname, sizeof(ifr.ifr_name))
1490 >= sizeof(ifr.ifr_name)) {
1491 error = ENAMETOOLONG;
1496 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
1497 if (space <= sizeof ifr)
1500 if (td->td_proc->p_ucred->cr_prison &&
1505 if (cmd == OSIOCGIFCONF) {
1506 struct osockaddr *osa =
1507 (struct osockaddr *)&ifr.ifr_addr;
1509 osa->sa_family = sa->sa_family;
1510 error = copyout(&ifr, ifrp, sizeof ifr);
1514 if (sa->sa_len <= sizeof(*sa)) {
1516 error = copyout(&ifr, ifrp, sizeof ifr);
1519 if (space < (sizeof ifr) + sa->sa_len -
1522 space -= sa->sa_len - sizeof(*sa);
1523 error = copyout(&ifr, ifrp,
1524 sizeof ifr.ifr_name);
1526 error = copyout(sa, &ifrp->ifr_addr,
1528 ifrp = (struct ifreq *)
1529 (sa->sa_len + (caddr_t)&ifrp->ifr_addr);
1533 space -= sizeof ifr;
1538 bzero(&ifr.ifr_addr, sizeof ifr.ifr_addr);
1539 error = copyout(&ifr, ifrp, sizeof ifr);
1542 space -= sizeof ifr;
1546 ifc->ifc_len -= space;
1551 * Just like if_promisc(), but for all-multicast-reception mode.
1554 if_allmulti(struct ifnet *ifp, int onswitch)
1562 if (ifp->if_amcount++ == 0) {
1563 ifp->if_flags |= IFF_ALLMULTI;
1564 ifr.ifr_flags = ifp->if_flags;
1565 ifr.ifr_flagshigh = ifp->if_flags >> 16;
1566 lwkt_serialize_enter(ifp->if_serializer);
1567 error = ifp->if_ioctl(ifp, SIOCSIFFLAGS, (caddr_t)&ifr,
1568 (struct ucred *)NULL);
1569 lwkt_serialize_exit(ifp->if_serializer);
1572 if (ifp->if_amcount > 1) {
1575 ifp->if_amcount = 0;
1576 ifp->if_flags &= ~IFF_ALLMULTI;
1577 ifr.ifr_flags = ifp->if_flags;
1578 ifr.ifr_flagshigh = ifp->if_flags >> 16;
1579 lwkt_serialize_enter(ifp->if_serializer);
1580 error = ifp->if_ioctl(ifp, SIOCSIFFLAGS, (caddr_t)&ifr,
1581 (struct ucred *)NULL);
1582 lwkt_serialize_exit(ifp->if_serializer);
1594 * Add a multicast listenership to the interface in question.
1595 * The link layer provides a routine which converts
1599 struct ifnet *ifp, /* interface to manipulate */
1600 struct sockaddr *sa, /* address to add */
1601 struct ifmultiaddr **retifma)
1603 struct sockaddr *llsa, *dupsa;
1605 struct ifmultiaddr *ifma;
1608 * If the matching multicast address already exists
1609 * then don't add a new one, just add a reference
1611 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1612 if (sa_equal(sa, ifma->ifma_addr)) {
1613 ifma->ifma_refcount++;
1621 * Give the link layer a chance to accept/reject it, and also
1622 * find out which AF_LINK address this maps to, if it isn't one
1625 if (ifp->if_resolvemulti) {
1626 lwkt_serialize_enter(ifp->if_serializer);
1627 error = ifp->if_resolvemulti(ifp, &llsa, sa);
1628 lwkt_serialize_exit(ifp->if_serializer);
1635 MALLOC(ifma, struct ifmultiaddr *, sizeof *ifma, M_IFMADDR, M_WAITOK);
1636 MALLOC(dupsa, struct sockaddr *, sa->sa_len, M_IFMADDR, M_WAITOK);
1637 bcopy(sa, dupsa, sa->sa_len);
1639 ifma->ifma_addr = dupsa;
1640 ifma->ifma_lladdr = llsa;
1641 ifma->ifma_ifp = ifp;
1642 ifma->ifma_refcount = 1;
1643 ifma->ifma_protospec = 0;
1644 rt_newmaddrmsg(RTM_NEWMADDR, ifma);
1647 * Some network interfaces can scan the address list at
1648 * interrupt time; lock them out.
1651 LIST_INSERT_HEAD(&ifp->if_multiaddrs, ifma, ifma_link);
1656 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1657 if (sa_equal(ifma->ifma_addr, llsa))
1661 ifma->ifma_refcount++;
1663 MALLOC(ifma, struct ifmultiaddr *, sizeof *ifma,
1664 M_IFMADDR, M_WAITOK);
1665 MALLOC(dupsa, struct sockaddr *, llsa->sa_len,
1666 M_IFMADDR, M_WAITOK);
1667 bcopy(llsa, dupsa, llsa->sa_len);
1668 ifma->ifma_addr = dupsa;
1669 ifma->ifma_ifp = ifp;
1670 ifma->ifma_refcount = 1;
1672 LIST_INSERT_HEAD(&ifp->if_multiaddrs, ifma, ifma_link);
1677 * We are certain we have added something, so call down to the
1678 * interface to let them know about it.
1681 lwkt_serialize_enter(ifp->if_serializer);
1682 ifp->if_ioctl(ifp, SIOCADDMULTI, 0, (struct ucred *)NULL);
1683 lwkt_serialize_exit(ifp->if_serializer);
1690 * Remove a reference to a multicast address on this interface. Yell
1691 * if the request does not match an existing membership.
1694 if_delmulti(struct ifnet *ifp, struct sockaddr *sa)
1696 struct ifmultiaddr *ifma;
1698 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
1699 if (sa_equal(sa, ifma->ifma_addr))
1704 if (ifma->ifma_refcount > 1) {
1705 ifma->ifma_refcount--;
1709 rt_newmaddrmsg(RTM_DELMADDR, ifma);
1710 sa = ifma->ifma_lladdr;
1712 LIST_REMOVE(ifma, ifma_link);
1714 * Make sure the interface driver is notified
1715 * in the case of a link layer mcast group being left.
1717 if (ifma->ifma_addr->sa_family == AF_LINK && sa == 0) {
1718 lwkt_serialize_enter(ifp->if_serializer);
1719 ifp->if_ioctl(ifp, SIOCDELMULTI, 0, (struct ucred *)NULL);
1720 lwkt_serialize_exit(ifp->if_serializer);
1723 free(ifma->ifma_addr, M_IFMADDR);
1724 free(ifma, M_IFMADDR);
1729 * Now look for the link-layer address which corresponds to
1730 * this network address. It had been squirreled away in
1731 * ifma->ifma_lladdr for this purpose (so we don't have
1732 * to call ifp->if_resolvemulti() again), and we saved that
1733 * value in sa above. If some nasty deleted the
1734 * link-layer address out from underneath us, we can deal because
1735 * the address we stored was is not the same as the one which was
1736 * in the record for the link-layer address. (So we don't complain
1739 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
1740 if (sa_equal(sa, ifma->ifma_addr))
1745 if (ifma->ifma_refcount > 1) {
1746 ifma->ifma_refcount--;
1751 lwkt_serialize_enter(ifp->if_serializer);
1752 LIST_REMOVE(ifma, ifma_link);
1753 ifp->if_ioctl(ifp, SIOCDELMULTI, 0, (struct ucred *)NULL);
1754 lwkt_serialize_exit(ifp->if_serializer);
1756 free(ifma->ifma_addr, M_IFMADDR);
1757 free(sa, M_IFMADDR);
1758 free(ifma, M_IFMADDR);
1764 * Set the link layer address on an interface.
1766 * At this time we only support certain types of interfaces,
1767 * and we don't allow the length of the address to change.
1770 if_setlladdr(struct ifnet *ifp, const u_char *lladdr, int len)
1772 struct sockaddr_dl *sdl;
1776 sdl = IF_LLSOCKADDR(ifp);
1779 if (len != sdl->sdl_alen) /* don't allow length to change */
1781 switch (ifp->if_type) {
1782 case IFT_ETHER: /* these types use struct arpcom */
1787 bcopy(lladdr, ((struct arpcom *)ifp->if_softc)->ac_enaddr, len);
1790 bcopy(lladdr, LLADDR(sdl), len);
1796 * If the interface is already up, we need
1797 * to re-init it in order to reprogram its
1800 lwkt_serialize_enter(ifp->if_serializer);
1801 if ((ifp->if_flags & IFF_UP) != 0) {
1802 ifp->if_flags &= ~IFF_UP;
1803 ifr.ifr_flags = ifp->if_flags;
1804 ifr.ifr_flagshigh = ifp->if_flags >> 16;
1805 ifp->if_ioctl(ifp, SIOCSIFFLAGS, (caddr_t)&ifr,
1806 (struct ucred *)NULL);
1807 ifp->if_flags |= IFF_UP;
1808 ifr.ifr_flags = ifp->if_flags;
1809 ifr.ifr_flagshigh = ifp->if_flags >> 16;
1810 ifp->if_ioctl(ifp, SIOCSIFFLAGS, (caddr_t)&ifr,
1811 (struct ucred *)NULL);
1814 * Also send gratuitous ARPs to notify other nodes about
1815 * the address change.
1817 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
1818 if (ifa->ifa_addr != NULL &&
1819 ifa->ifa_addr->sa_family == AF_INET)
1820 arp_ifinit(ifp, ifa);
1824 lwkt_serialize_exit(ifp->if_serializer);
1828 struct ifmultiaddr *
1829 ifmaof_ifpforaddr(struct sockaddr *sa, struct ifnet *ifp)
1831 struct ifmultiaddr *ifma;
1833 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
1834 if (sa_equal(ifma->ifma_addr, sa))
1841 * The name argument must be a pointer to storage which will last as
1842 * long as the interface does. For physical devices, the result of
1843 * device_get_name(dev) is a good choice and for pseudo-devices a
1844 * static string works well.
1847 if_initname(struct ifnet *ifp, const char *name, int unit)
1849 ifp->if_dname = name;
1850 ifp->if_dunit = unit;
1851 if (unit != IF_DUNIT_NONE)
1852 snprintf(ifp->if_xname, IFNAMSIZ, "%s%d", name, unit);
1854 strlcpy(ifp->if_xname, name, IFNAMSIZ);
1858 if_printf(struct ifnet *ifp, const char *fmt, ...)
1863 retval = printf("%s: ", ifp->if_xname);
1864 __va_start(ap, fmt);
1865 retval += vprintf(fmt, ap);
1870 SYSCTL_NODE(_net, PF_LINK, link, CTLFLAG_RW, 0, "Link layers");
1871 SYSCTL_NODE(_net_link, 0, generic, CTLFLAG_RW, 0, "Generic link-management");
1874 ifq_set_classic(struct ifaltq *ifq)
1876 ifq->altq_enqueue = ifq_classic_enqueue;
1877 ifq->altq_dequeue = ifq_classic_dequeue;
1878 ifq->altq_request = ifq_classic_request;
1882 ifq_classic_enqueue(struct ifaltq *ifq, struct mbuf *m,
1883 struct altq_pktattr *pa __unused)
1886 if (IF_QFULL(ifq)) {
1897 static struct mbuf *
1898 ifq_classic_dequeue(struct ifaltq *ifq, struct mbuf *mpolled, int op)
1911 panic("unsupported ALTQ dequeue op: %d", op);
1914 KKASSERT(mpolled == NULL || mpolled == m);
1919 ifq_classic_request(struct ifaltq *ifq, int req, void *arg)
1927 panic("unspported ALTQ request: %d", req);