📄 if_var.h
字号:
#define IF_ENQUEUE(ifq, m) do { \ IF_LOCK(ifq); \ _IF_ENQUEUE(ifq, m); \ IF_UNLOCK(ifq); \} while (0)#define _IF_PREPEND(ifq, m) do { \ (m)->m_nextpkt = (ifq)->ifq_head; \ if ((ifq)->ifq_tail == NULL) \ (ifq)->ifq_tail = (m); \ (ifq)->ifq_head = (m); \ (ifq)->ifq_len++; \} while (0)#define IF_PREPEND(ifq, m) do { \ IF_LOCK(ifq); \ _IF_PREPEND(ifq, m); \ IF_UNLOCK(ifq); \} while (0)#define _IF_DEQUEUE(ifq, m) do { \ (m) = (ifq)->ifq_head; \ if (m) { \ if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \ (ifq)->ifq_tail = NULL; \ (m)->m_nextpkt = NULL; \ (ifq)->ifq_len--; \ } \} while (0)#define IF_DEQUEUE(ifq, m) do { \ IF_LOCK(ifq); \ _IF_DEQUEUE(ifq, m); \ IF_UNLOCK(ifq); \} while (0)#define IF_DRAIN(ifq) do { \ struct mbuf *m; \ IF_LOCK(ifq); \ for (;;) { \ _IF_DEQUEUE(ifq, m); \ if (m == NULL) \ break; \ m_freem(m); \ } \ IF_UNLOCK(ifq); \} while (0)#ifdef _KERNEL#define IF_HANDOFF(ifq, m, ifp) if_handoff(ifq, m, ifp, 0)#define IF_HANDOFF_ADJ(ifq, m, ifp, adj) if_handoff(ifq, m, ifp, adj)static __inline intif_handoff(struct ifqueue *ifq, struct mbuf *m, struct ifnet *ifp, int adjust){ int active = 0; IF_LOCK(ifq); if (_IF_QFULL(ifq)) { _IF_DROP(ifq); IF_UNLOCK(ifq); m_freem(m); return (0); } if (ifp != NULL) { ifp->if_obytes += m->m_pkthdr.len + adjust; if (m->m_flags & M_MCAST) ifp->if_omcasts++; active = ifp->if_flags & IFF_OACTIVE; } _IF_ENQUEUE(ifq, m); IF_UNLOCK(ifq); if (ifp != NULL && !active) (*ifp->if_start)(ifp); return (1);}/* * 72 was chosen below because it is the size of a TCP/IP * header (40) + the minimum mss (32). */#define IF_MINMTU 72#define IF_MAXMTU 65535#endif /* _KERNEL *//* * The ifaddr structure contains information about one address * of an interface. They are maintained by the different address families, * are allocated and attached when an address is set, and are linked * together so all addresses for an interface can be located. */struct ifaddr { struct sockaddr *ifa_addr; /* address of interface */ struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ struct sockaddr *ifa_netmask; /* used to determine subnet */ struct if_data if_data; /* not all members are meaningful */ struct ifnet *ifa_ifp; /* back-pointer to interface */ TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */ void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */ (int, struct rtentry *, struct rt_addrinfo *); u_short ifa_flags; /* mostly rt_flags for cloning */ u_int ifa_refcnt; /* references to this structure */ int ifa_metric; /* cost of going out this interface */#ifdef notdef struct rtentry *ifa_rt; /* XXXX for ROUTETOIF ????? */#endif int (*ifa_claim_addr) /* check if an addr goes to this if */ (struct ifaddr *, struct sockaddr *);};#define IFA_ROUTE RTF_UP /* route installed *//* for compatibility with other BSDs */#define ifa_list ifa_link/* * The prefix structure contains information about one prefix * of an interface. They are maintained by the different address families, * are allocated and attached when an prefix or an address is set, * and are linked together so all prefixes for an interface can be located. */struct ifprefix { struct sockaddr *ifpr_prefix; /* prefix of interface */ struct ifnet *ifpr_ifp; /* back-pointer to interface */ TAILQ_ENTRY(ifprefix) ifpr_list; /* queue macro glue */ u_char ifpr_plen; /* prefix length in bits */ u_char ifpr_type; /* protocol dependent prefix type */};/* * Multicast address structure. This is analogous to the ifaddr * structure except that it keeps track of multicast addresses. * Also, the reference count here is a count of requests for this * address, not a count of pointers to this structure. */struct ifmultiaddr { TAILQ_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */ struct sockaddr *ifma_addr; /* address this membership is for */ struct sockaddr *ifma_lladdr; /* link-layer translation, if any */ struct ifnet *ifma_ifp; /* back-pointer to interface */ u_int ifma_refcount; /* reference count */ void *ifma_protospec; /* protocol-specific state, if any */};#ifdef _KERNEL#define IFAFREE(ifa) \ do { \ if ((ifa)->ifa_refcnt <= 0) \ ifafree(ifa); \ else \ (ifa)->ifa_refcnt--; \ } while (0)struct ifindex_entry { struct ifnet *ife_ifnet; struct ifaddr *ife_ifnet_addr; dev_t ife_dev;};#define ifnet_byindex(idx) ifindex_table[(idx)].ife_ifnet#define ifaddr_byindex(idx) ifindex_table[(idx)].ife_ifnet_addr#define ifdev_byindex(idx) ifindex_table[(idx)].ife_devextern struct ifnethead ifnet;extern struct ifindex_entry *ifindex_table;extern int ifqmaxlen;extern struct ifnet *loif; /* first loopback interface */extern int if_index;void ether_ifattach(struct ifnet *, int);void ether_ifdetach(struct ifnet *, int);void ether_input(struct ifnet *, struct ether_header *, struct mbuf *);void ether_demux(struct ifnet *, struct ether_header *, struct mbuf *);int ether_output(struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *);int ether_output_frame(struct ifnet *, struct mbuf *);int ether_ioctl(struct ifnet *, int, caddr_t);int if_addmulti(struct ifnet *, struct sockaddr *, struct ifmultiaddr **);int if_allmulti(struct ifnet *, int);void if_attach(struct ifnet *);int if_delmulti(struct ifnet *, struct sockaddr *);void if_detach(struct ifnet *);void if_down(struct ifnet *);void if_route(struct ifnet *, int flag, int fam);int if_setlladdr(struct ifnet *, const u_char *, int);void if_unroute(struct ifnet *, int flag, int fam);void if_up(struct ifnet *);/*void ifinit(void);*/ /* declared in systm.h for main() */int ifioctl(struct socket *, u_long, caddr_t, struct thread *);int ifpromisc(struct ifnet *, int);struct ifnet *ifunit(const char *);struct ifnet *if_withname(struct sockaddr *);int if_poll_recv_slow(struct ifnet *ifp, int *quotap);void if_poll_xmit_slow(struct ifnet *ifp, int *quotap);void if_poll_throttle(void);void if_poll_unthrottle(void *);void if_poll_init(void);void if_poll(void);struct ifaddr *ifa_ifwithaddr(struct sockaddr *);struct ifaddr *ifa_ifwithdstaddr(struct sockaddr *);struct ifaddr *ifa_ifwithnet(struct sockaddr *);struct ifaddr *ifa_ifwithroute(int, struct sockaddr *, struct sockaddr *);struct ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *);void ifafree(struct ifaddr *);struct ifmultiaddr *ifmaof_ifpforaddr(struct sockaddr *, struct ifnet *);int if_simloop(struct ifnet *ifp, struct mbuf *m, int af, int hlen);void if_clone_attach(struct if_clone *);void if_clone_detach(struct if_clone *);int if_clone_create(char *, int);int if_clone_destroy(const char *);#define IF_LLADDR(ifp) \ LLADDR((struct sockaddr_dl *) ifaddr_byindex((ifp)->if_index)->ifa_addr)#ifdef DEVICE_POLLINGenum poll_cmd { POLL_ONLY, POLL_AND_CHECK_STATUS, POLL_DEREGISTER };typedef void poll_handler_t(struct ifnet *ifp, enum poll_cmd cmd, int count);int ether_poll_register(poll_handler_t *h, struct ifnet *ifp);int ether_poll_deregister(struct ifnet *ifp);#endif /* DEVICE_POLLING */#endif /* _KERNEL */#endif /* !_NET_IF_VAR_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -