Deleted Added
full compact
if.c (185088) if.c (185162)
1/*-
2 * Copyright (c) 1980, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)if.c 8.5 (Berkeley) 1/9/95
1/*-
2 * Copyright (c) 1980, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)if.c 8.5 (Berkeley) 1/9/95
30 * $FreeBSD: head/sys/net/if.c 185088 2008-11-19 09:39:34Z zec $
30 * $FreeBSD: head/sys/net/if.c 185162 2008-11-22 05:55:56Z kmacy $
31 */
32
33#include "opt_compat.h"
34#include "opt_inet6.h"
35#include "opt_inet.h"
36#include "opt_mac.h"
37#include "opt_carp.h"
38

--- 69 unchanged lines hidden (view full) ---

108 * declaration order.
109 */
110static void if_attachdomain(void *);
111static void if_attachdomain1(struct ifnet *);
112static int ifconf(u_long, caddr_t);
113static void if_freemulti(struct ifmultiaddr *);
114static void if_grow(void);
115static void if_init(void *);
31 */
32
33#include "opt_compat.h"
34#include "opt_inet6.h"
35#include "opt_inet.h"
36#include "opt_mac.h"
37#include "opt_carp.h"
38

--- 69 unchanged lines hidden (view full) ---

108 * declaration order.
109 */
110static void if_attachdomain(void *);
111static void if_attachdomain1(struct ifnet *);
112static int ifconf(u_long, caddr_t);
113static void if_freemulti(struct ifmultiaddr *);
114static void if_grow(void);
115static void if_init(void *);
116static void if_qflush(struct ifaltq *);
116static void if_qflush(struct ifnet *);
117static void if_route(struct ifnet *, int flag, int fam);
118static int if_setflag(struct ifnet *, int, int, int *, int);
119static void if_slowtimo(void *);
117static void if_route(struct ifnet *, int flag, int fam);
118static int if_setflag(struct ifnet *, int, int, int *, int);
119static void if_slowtimo(void *);
120static int if_transmit(struct ifnet *ifp, struct mbuf *m);
120static void if_unroute(struct ifnet *, int flag, int fam);
121static void link_rtrequest(int, struct rtentry *, struct rt_addrinfo *);
122static int if_rtdel(struct radix_node *, void *);
123static int ifhwioctl(u_long, struct ifnet *, caddr_t, struct thread *);
124static int if_delmulti_locked(struct ifnet *, struct ifmultiaddr *, int);
125static void if_start_deferred(void *context, int pending);
126static void do_link_state_change(void *, int);
127static int if_getgroup(struct ifgroupreq *, struct ifnet *);
128static int if_getgroupmembers(struct ifgroupreq *);
121static void if_unroute(struct ifnet *, int flag, int fam);
122static void link_rtrequest(int, struct rtentry *, struct rt_addrinfo *);
123static int if_rtdel(struct radix_node *, void *);
124static int ifhwioctl(u_long, struct ifnet *, caddr_t, struct thread *);
125static int if_delmulti_locked(struct ifnet *, struct ifmultiaddr *, int);
126static void if_start_deferred(void *context, int pending);
127static void do_link_state_change(void *, int);
128static int if_getgroup(struct ifgroupreq *, struct ifnet *);
129static int if_getgroupmembers(struct ifgroupreq *);
130
129#ifdef INET6
130/*
131 * XXX: declare here to avoid to include many inet6 related files..
132 * should be more generalized?
133 */
134extern void nd6_setmtu(struct ifnet *);
135#endif
136

--- 339 unchanged lines hidden (view full) ---

476
477 if (if_com_free[type] != NULL)
478 if_com_free[type](ifp->if_l2com, type);
479
480 IF_ADDR_LOCK_DESTROY(ifp);
481 free(ifp, M_IFNET);
482};
483
131#ifdef INET6
132/*
133 * XXX: declare here to avoid to include many inet6 related files..
134 * should be more generalized?
135 */
136extern void nd6_setmtu(struct ifnet *);
137#endif
138

--- 339 unchanged lines hidden (view full) ---

478
479 if (if_com_free[type] != NULL)
480 if_com_free[type](ifp->if_l2com, type);
481
482 IF_ADDR_LOCK_DESTROY(ifp);
483 free(ifp, M_IFNET);
484};
485
486void
487ifq_attach(struct ifaltq *ifq, struct ifnet *ifp)
488{
489
490 mtx_init(&ifq->ifq_mtx, ifp->if_xname, "if send queue", MTX_DEF);
491
492 if (ifq->ifq_maxlen == 0)
493 ifq->ifq_maxlen = ifqmaxlen;
494
495 ifq->altq_type = 0;
496 ifq->altq_disc = NULL;
497 ifq->altq_flags &= ALTQF_CANTCHANGE;
498 ifq->altq_tbr = NULL;
499 ifq->altq_ifp = ifp;
500}
501
502void
503ifq_detach(struct ifaltq *ifq)
504{
505 mtx_destroy(&ifq->ifq_mtx);
506}
507
484/*
485 * Perform generic interface initalization tasks and attach the interface
486 * to the list of "active" interfaces.
487 *
488 * XXX:
489 * - The decision to return void and thus require this function to
490 * succeed is questionable.
491 * - We do more initialization here then is probably a good idea.

--- 25 unchanged lines hidden (view full) ---

517 TAILQ_INIT(&ifp->if_groups);
518
519 if_addgroup(ifp, IFG_ALL);
520
521 knlist_init(&ifp->if_klist, NULL, NULL, NULL, NULL);
522 getmicrotime(&ifp->if_lastchange);
523 ifp->if_data.ifi_epoch = time_uptime;
524 ifp->if_data.ifi_datalen = sizeof(struct if_data);
508/*
509 * Perform generic interface initalization tasks and attach the interface
510 * to the list of "active" interfaces.
511 *
512 * XXX:
513 * - The decision to return void and thus require this function to
514 * succeed is questionable.
515 * - We do more initialization here then is probably a good idea.

--- 25 unchanged lines hidden (view full) ---

541 TAILQ_INIT(&ifp->if_groups);
542
543 if_addgroup(ifp, IFG_ALL);
544
545 knlist_init(&ifp->if_klist, NULL, NULL, NULL, NULL);
546 getmicrotime(&ifp->if_lastchange);
547 ifp->if_data.ifi_epoch = time_uptime;
548 ifp->if_data.ifi_datalen = sizeof(struct if_data);
525
549 ifp->if_transmit = if_transmit;
550 ifp->if_qflush = if_qflush;
526#ifdef MAC
527 mac_ifnet_init(ifp);
528 mac_ifnet_create(ifp);
529#endif
530
531 ifdev_setbyindex(ifp->if_index, make_dev(&net_cdevsw,
532 ifp->if_index, UID_ROOT, GID_WHEEL, 0600, "%s/%s",
533 net_cdevsw.d_name, ifp->if_xname));
534 make_dev_alias(ifdev_byindex(ifp->if_index), "%s%d",
535 net_cdevsw.d_name, ifp->if_index);
536
551#ifdef MAC
552 mac_ifnet_init(ifp);
553 mac_ifnet_create(ifp);
554#endif
555
556 ifdev_setbyindex(ifp->if_index, make_dev(&net_cdevsw,
557 ifp->if_index, UID_ROOT, GID_WHEEL, 0600, "%s/%s",
558 net_cdevsw.d_name, ifp->if_xname));
559 make_dev_alias(ifdev_byindex(ifp->if_index), "%s%d",
560 net_cdevsw.d_name, ifp->if_index);
561
537 mtx_init(&ifp->if_snd.ifq_mtx, ifp->if_xname, "if send queue", MTX_DEF);
562 ifq_attach(&ifp->if_snd, ifp);
538
539 /*
540 * create a Link Level name for this device
541 */
542 namelen = strlen(ifp->if_xname);
543 /*
544 * Always save enough space for any possiable name so we can do
545 * a rename in place later.

--- 21 unchanged lines hidden (view full) ---

567 ifa->ifa_netmask = (struct sockaddr *)sdl;
568 sdl->sdl_len = masklen;
569 while (namelen != 0)
570 sdl->sdl_data[--namelen] = 0xff;
571 ifa->ifa_refcnt = 1;
572 TAILQ_INSERT_HEAD(&ifp->if_addrhead, ifa, ifa_link);
573 ifp->if_broadcastaddr = NULL; /* reliably crash if used uninitialized */
574
563
564 /*
565 * create a Link Level name for this device
566 */
567 namelen = strlen(ifp->if_xname);
568 /*
569 * Always save enough space for any possiable name so we can do
570 * a rename in place later.

--- 21 unchanged lines hidden (view full) ---

592 ifa->ifa_netmask = (struct sockaddr *)sdl;
593 sdl->sdl_len = masklen;
594 while (namelen != 0)
595 sdl->sdl_data[--namelen] = 0xff;
596 ifa->ifa_refcnt = 1;
597 TAILQ_INSERT_HEAD(&ifp->if_addrhead, ifa, ifa_link);
598 ifp->if_broadcastaddr = NULL; /* reliably crash if used uninitialized */
599
575 /*
576 * XXX: why do we warn about this? We're correcting it and most
577 * drivers just set the value the way we do.
578 */
579 if (ifp->if_snd.ifq_maxlen == 0) {
580 if_printf(ifp, "XXX: driver didn't set ifq_maxlen\n");
581 ifp->if_snd.ifq_maxlen = ifqmaxlen;
582 }
583 ifp->if_snd.altq_type = 0;
584 ifp->if_snd.altq_disc = NULL;
585 ifp->if_snd.altq_flags &= ALTQF_CANTCHANGE;
586 ifp->if_snd.altq_tbr = NULL;
587 ifp->if_snd.altq_ifp = ifp;
588
589 IFNET_WLOCK();
590 TAILQ_INSERT_TAIL(&V_ifnet, ifp, if_link);
591 IFNET_WUNLOCK();
592
593 if (domain_init_status >= 2)
594 if_attachdomain1(ifp);
595

--- 225 unchanged lines hidden (view full) ---

821 IF_AFDATA_UNLOCK(ifp);
822
823#ifdef MAC
824 mac_ifnet_destroy(ifp);
825#endif /* MAC */
826 KNOTE_UNLOCKED(&ifp->if_klist, NOTE_EXIT);
827 knlist_clear(&ifp->if_klist, 0);
828 knlist_destroy(&ifp->if_klist);
600
601 IFNET_WLOCK();
602 TAILQ_INSERT_TAIL(&V_ifnet, ifp, if_link);
603 IFNET_WUNLOCK();
604
605 if (domain_init_status >= 2)
606 if_attachdomain1(ifp);
607

--- 225 unchanged lines hidden (view full) ---

833 IF_AFDATA_UNLOCK(ifp);
834
835#ifdef MAC
836 mac_ifnet_destroy(ifp);
837#endif /* MAC */
838 KNOTE_UNLOCKED(&ifp->if_klist, NOTE_EXIT);
839 knlist_clear(&ifp->if_klist, 0);
840 knlist_destroy(&ifp->if_klist);
829 mtx_destroy(&ifp->if_snd.ifq_mtx);
841 ifq_detach(&ifp->if_snd);
830 IF_AFDATA_DESTROY(ifp);
831 splx(s);
832}
833
834/*
835 * Add a group to an interface
836 */
837int

--- 534 unchanged lines hidden (view full) ---

1372
1373 KASSERT(flag == IFF_UP, ("if_unroute: flag != IFF_UP"));
1374
1375 ifp->if_flags &= ~flag;
1376 getmicrotime(&ifp->if_lastchange);
1377 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
1378 if (fam == PF_UNSPEC || (fam == ifa->ifa_addr->sa_family))
1379 pfctlinput(PRC_IFDOWN, ifa->ifa_addr);
842 IF_AFDATA_DESTROY(ifp);
843 splx(s);
844}
845
846/*
847 * Add a group to an interface
848 */
849int

--- 534 unchanged lines hidden (view full) ---

1384
1385 KASSERT(flag == IFF_UP, ("if_unroute: flag != IFF_UP"));
1386
1387 ifp->if_flags &= ~flag;
1388 getmicrotime(&ifp->if_lastchange);
1389 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
1390 if (fam == PF_UNSPEC || (fam == ifa->ifa_addr->sa_family))
1391 pfctlinput(PRC_IFDOWN, ifa->ifa_addr);
1380 if_qflush(&ifp->if_snd);
1392 ifp->if_qflush(ifp);
1393
1381#ifdef DEV_CARP
1382 if (ifp->if_carp)
1383 carp_carpdev_state(ifp->if_carp);
1384#endif
1385 rt_ifmsg(ifp);
1386}
1387
1388/*

--- 113 unchanged lines hidden (view full) ---

1502
1503 if_route(ifp, IFF_UP, AF_UNSPEC);
1504}
1505
1506/*
1507 * Flush an interface queue.
1508 */
1509static void
1394#ifdef DEV_CARP
1395 if (ifp->if_carp)
1396 carp_carpdev_state(ifp->if_carp);
1397#endif
1398 rt_ifmsg(ifp);
1399}
1400
1401/*

--- 113 unchanged lines hidden (view full) ---

1515
1516 if_route(ifp, IFF_UP, AF_UNSPEC);
1517}
1518
1519/*
1520 * Flush an interface queue.
1521 */
1522static void
1510if_qflush(struct ifaltq *ifq)
1523if_qflush(struct ifnet *ifp)
1511{
1512 struct mbuf *m, *n;
1524{
1525 struct mbuf *m, *n;
1513
1526 struct ifaltq *ifq;
1527
1528 ifq = &ifp->if_snd;
1514 IFQ_LOCK(ifq);
1515#ifdef ALTQ
1516 if (ALTQ_IS_ENABLED(ifq))
1517 ALTQ_PURGE(ifq);
1518#endif
1519 n = ifq->ifq_head;
1520 while ((m = n) != 0) {
1521 n = m->m_act;

--- 1274 unchanged lines hidden (view full) ---

2796 struct ifnet *ifp;
2797
2798 GIANT_REQUIRED;
2799
2800 ifp = context;
2801 (ifp->if_start)(ifp);
2802}
2803
1529 IFQ_LOCK(ifq);
1530#ifdef ALTQ
1531 if (ALTQ_IS_ENABLED(ifq))
1532 ALTQ_PURGE(ifq);
1533#endif
1534 n = ifq->ifq_head;
1535 while ((m = n) != 0) {
1536 n = m->m_act;

--- 1274 unchanged lines hidden (view full) ---

2811 struct ifnet *ifp;
2812
2813 GIANT_REQUIRED;
2814
2815 ifp = context;
2816 (ifp->if_start)(ifp);
2817}
2818
2819/*
2820 * Backwards compatibility interface for drivers
2821 * that have not implemented it
2822 */
2823static int
2824if_transmit(struct ifnet *ifp, struct mbuf *m)
2825{
2826 int error;
2827
2828 IFQ_HANDOFF(ifp, m, error);
2829 return (error);
2830}
2831
2804int
2805if_handoff(struct ifqueue *ifq, struct mbuf *m, struct ifnet *ifp, int adjust)
2806{
2807 int active = 0;
2808
2809 IF_LOCK(ifq);
2810 if (_IF_QFULL(ifq)) {
2811 _IF_DROP(ifq);

--- 42 unchanged lines hidden ---
2832int
2833if_handoff(struct ifqueue *ifq, struct mbuf *m, struct ifnet *ifp, int adjust)
2834{
2835 int active = 0;
2836
2837 IF_LOCK(ifq);
2838 if (_IF_QFULL(ifq)) {
2839 _IF_DROP(ifq);

--- 42 unchanged lines hidden ---