Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / ipfilter / ipsend / in_var.h
1 /*      @(#)in_var.h 1.3 88/08/19 SMI; from UCB 7.1 6/5/86      */
2
3 /*
4  * Copyright (c) 1985, 1986 Regents of the University of California.
5  * All rights reserved.  The Berkeley software License Agreement
6  * specifies the terms and conditions for redistribution.
7  */
8
9 /*
10  * Interface address, Internet version.  One of these structures
11  * is allocated for each interface with an Internet address.
12  * The ifaddr structure contains the protocol-independent part
13  * of the structure and is assumed to be first.
14  */
15
16 #ifndef _netinet_in_var_h
17 #define _netinet_in_var_h
18
19 struct in_ifaddr {
20         struct  ifaddr ia_ifa;          /* protocol-independent info */
21 #define ia_addr ia_ifa.ifa_addr
22 #define ia_broadaddr    ia_ifa.ifa_broadaddr
23 #define ia_dstaddr      ia_ifa.ifa_dstaddr
24 #define ia_ifp          ia_ifa.ifa_ifp
25         u_long  ia_net;                 /* network number of interface */
26         u_long  ia_netmask;             /* mask of net part */
27         u_long  ia_subnet;              /* subnet number, including net */
28         u_long  ia_subnetmask;          /* mask of net + subnet */
29         struct  in_addr ia_netbroadcast; /* broadcast addr for (logical) net */
30         int     ia_flags;
31         struct  in_ifaddr *ia_next;     /* next in list of internet addresses */
32         struct  in_multi *ia_multiaddrs;/* list of multicast addresses */
33 };
34 /*
35  * Given a pointer to an in_ifaddr (ifaddr),
36  * return a pointer to the addr as a sockadd_in.
37  */
38 #define IA_SIN(ia) ((struct sockaddr_in *)(&((struct in_ifaddr *)ia)->ia_addr))
39 /*
40  * ia_flags
41  */
42 #define IFA_ROUTE       0x01            /* routing entry installed */
43
44 #ifdef  KERNEL
45 struct  in_ifaddr *in_ifaddr;
46 struct  in_ifaddr *in_iaonnetof();
47 struct  ifqueue ipintrq;                /* ip packet input queue */
48 #endif
49
50 #ifdef KERNEL
51 /*
52  * Macro for finding the interface (ifnet structure) corresponding to one
53  * of our IP addresses.
54  */
55 #define INADDR_TO_IFP(addr, ifp)                                          \
56         /* struct in_addr addr; */                                        \
57         /* struct ifnet  *ifp;  */                                        \
58 {                                                                         \
59         register struct in_ifaddr *ia;                                    \
60                                                                           \
61         for (ia = in_ifaddr;                                              \
62              ia != NULL && IA_SIN(ia)->sin_addr.s_addr != (addr).s_addr;  \
63              ia = ia->ia_next);                                           \
64         (ifp) = (ia == NULL) ? NULL : ia->ia_ifp;                         \
65 }
66
67 /*
68  * Macro for finding the internet address structure (in_ifaddr) corresponding
69  * to a given interface (ifnet structure).
70  */
71 #define IFP_TO_IA(ifp, ia)                                                \
72         /* struct ifnet     *ifp; */                                      \
73         /* struct in_ifaddr *ia;  */                                      \
74 {                                                                         \
75         for ((ia) = in_ifaddr;                                            \
76              (ia) != NULL && (ia)->ia_ifp != (ifp);                       \
77              (ia) = (ia)->ia_next);                                       \
78 }
79 #endif KERNEL
80
81 /*
82  * Per-interface router version information is kept in this list.
83  * This information should be part of the ifnet structure but we don't wish
84  * to change that - as it might break a number of things
85  */
86
87 struct router_info {
88         struct ifnet *ifp;
89         int    type; /* type of router which is querier on this interface */
90         int    time; /* # of slow timeouts since last old query */
91         struct router_info *next;
92 };
93
94 /*
95  * Internet multicast address structure.  There is one of these for each IP
96  * multicast group to which this host belongs on a given network interface.
97  * They are kept in a linked list, rooted in the interface's in_ifaddr
98  * structure.
99  */
100
101 struct in_multi {
102         struct in_addr     inm_addr;    /* IP multicast address             */
103         struct ifnet      *inm_ifp;     /* back pointer to ifnet            */
104         struct in_ifaddr  *inm_ia;      /* back pointer to in_ifaddr        */
105         u_int              inm_refcount;/* no. membership claims by sockets */
106         u_int              inm_timer;   /* IGMP membership report timer     */
107         struct in_multi   *inm_next;    /* ptr to next multicast address    */
108         u_int              inm_state;   /*  state of the membership */
109         struct router_info *inm_rti;     /* router info*/
110 };
111
112 #ifdef KERNEL
113 /*
114  * Structure used by macros below to remember position when stepping through
115  * all of the in_multi records.
116  */
117 struct in_multistep {
118         struct in_ifaddr *i_ia;
119         struct in_multi  *i_inm;
120 };
121
122 /*
123  * Macro for looking up the in_multi record for a given IP multicast address
124  * on a given interface.  If no matching record is found, "inm" returns NULL.
125  */
126 #define IN_LOOKUP_MULTI(addr, ifp, inm)                                     \
127         /* struct in_addr  addr; */                                         \
128         /* struct ifnet    *ifp; */                                         \
129         /* struct in_multi *inm; */                                         \
130 {                                                                           \
131         register struct in_ifaddr *ia;                                      \
132                                                                             \
133         IFP_TO_IA((ifp), ia);                                               \
134         if (ia == NULL)                                                     \
135                 (inm) = NULL;                                               \
136         else                                                                \
137             for ((inm) = ia->ia_multiaddrs;                                 \
138                  (inm) != NULL && (inm)->inm_addr.s_addr != (addr).s_addr;  \
139                  (inm) = inm->inm_next);                                    \
140 }
141
142 /*
143  * Macro to step through all of the in_multi records, one at a time.
144  * The current position is remembered in "step", which the caller must
145  * provide.  IN_FIRST_MULTI(), below, must be called to initialize "step"
146  * and get the first record.  Both macros return a NULL "inm" when there
147  * are no remaining records.
148  */
149 #define IN_NEXT_MULTI(step, inm)                                        \
150         /* struct in_multistep  step; */                                \
151         /* struct in_multi     *inm;  */                                \
152 {                                                                       \
153         if (((inm) = (step).i_inm) != NULL) {                           \
154                 (step).i_inm = (inm)->inm_next;                         \
155         }                                                               \
156         else while ((step).i_ia != NULL) {                              \
157                 (inm) = (step).i_ia->ia_multiaddrs;                     \
158                 (step).i_ia = (step).i_ia->ia_next;                     \
159                 if ((inm) != NULL) {                                    \
160                         (step).i_inm = (inm)->inm_next;                 \
161                         break;                                          \
162                 }                                                       \
163         }                                                               \
164 }
165
166 #define IN_FIRST_MULTI(step, inm)                                       \
167         /* struct in_multistep  step; */                                \
168         /* struct in_multi     *inm;  */                                \
169 {                                                                       \
170         (step).i_ia  = in_ifaddr;                                       \
171         (step).i_inm = NULL;                                            \
172         IN_NEXT_MULTI((step), (inm));                                   \
173 }
174
175 struct in_multi *in_addmulti();
176 #endif KERNEL
177 #endif /*!_netinet_in_var_h*/