xref: /haiku/headers/posix/net/route.h (revision 7120e97489acbf17d86d3f33e3b2e68974fd4b23)
1 /* route.h */
2 
3 #ifndef _NET_ROUTE_H
4 #define _NET_ROUTE_H
5 
6 #include <net/radix.h>
7 #include <sys/socket.h> /* for AF_MAX */
8 /*
9  * A route consists of a destination address and a reference
10  * to a routing entry.  These are often held by protocols
11  * in their control blocks, e.g. inpcb.
12  */
13 struct route {
14         struct  rtentry *ro_rt;
15         struct  sockaddr ro_dst;
16 };
17 
18 /*
19  * These numbers are used by reliable protocols for determining
20  * retransmission behavior and are included in the routing structure.
21  */
22 struct rt_metrics {
23         uint32  rmx_locks;      /* Kernel must leave these values alone */
24         uint32  rmx_mtu;        /* MTU for this path */
25         uint32  rmx_hopcount;   /* max hops expected */
26         uint32  rmx_expire;     /* lifetime for route, e.g. redirect */
27         u_long  rmx_recvpipe;   /* inbound delay-bandwith product */
28         u_long  rmx_sendpipe;   /* outbound delay-bandwith product */
29         u_long  rmx_ssthresh;   /* outbound gateway buffer limit */
30         u_long  rmx_rtt;        /* estimated round trip time */
31         u_long  rmx_rttvar;     /* estimated rtt variance */
32         u_long  rmx_pksent;     /* packets sent using this route */
33 };
34 
35 /*
36  * rmx_rtt and rmx_rttvar are stored as microseconds;
37  * RTTTOPRHZ(rtt) converts to a value suitable for use
38  * by a protocol slowtimo counter.
39  */
40 #define	RTM_RTTUNIT     1000000 /* units for rtt, rttvar, as units per sec */
41 #define	RTTTOPRHZ(r)	((r) / (RTM_RTTUNIT / PR_SLOWHZ))
42 
43 struct rtentry {
44         struct  radix_node rt_nodes[2]; /* tree glue, and other values */
45         struct  sockaddr *rt_gateway;   /* value */
46         uint	rt_flags;               /* up/down?, host/net */
47         int     rt_refcnt;              /* # held references */
48         uint32	rt_use;                 /* raw # packets forwarded */
49         struct  ifnet  *rt_ifp;         /* the answer: interface to use */
50         struct  ifaddr *rt_ifa;         /* the answer: interface to use */
51         struct  sockaddr *rt_genmask;   /* for generation of cloned routes */
52         char *  rt_llinfo;              /* pointer to link level info cache */
53         struct  rt_metrics rt_rmx;      /* metrics used by rx'ing protocols */
54         struct  rtentry *rt_gwroute;    /* implied entry for gatewayed routes */
55         struct  rtentry *rt_parent;     /* If cloned, parent of this route. */
56 	/* XXX - add this! */
57         // rt_timer;  * queue of timeouts for misc funcs *
58 };
59 #define rt_use          rt_rmx.rmx_pksent
60 #define rt_key(r)       ((struct sockaddr *)((r)->rt_nodes->rn_key))
61 #define rt_mask(r)      ((struct sockaddr *)((r)->rt_nodes->rn_mask))
62 
63 #define RTF_UP          0x1             /* route usable */
64 #define RTF_GATEWAY     0x2             /* destination is a gateway */
65 #define RTF_HOST        0x4             /* host entry (net otherwise) */
66 #define RTF_REJECT      0x8             /* host or net unreachable */
67 #define RTF_DYNAMIC     0x10            /* created dynamically (by redirect) */
68 #define RTF_MODIFIED    0x20            /* modified dynamically (by redirect) */
69 #define RTF_DONE        0x40            /* message confirmed */
70 #define RTF_MASK        0x80            /* subnet mask present */
71 #define RTF_CLONING     0x100           /* generate new routes on use */
72 #define RTF_XRESOLVE    0x200           /* external daemon resolves name */
73 #define RTF_LLINFO      0x400           /* generated by ARP or ESIS */
74 #define RTF_STATIC      0x800           /* manually added */
75 #define RTF_BLACKHOLE   0x1000          /* just discard pkts (during updates) */
76 #define RTF_PROTO3      0x2000          /* protocol specific routing flag */
77 #define RTF_PROTO2      0x4000          /* protocol specific routing flag */
78 #define RTF_PROTO1      0x8000          /* protocol specific routing flag */
79 
80 #define RTM_VERSION     3       /* Up the ante and ignore older versions */
81 
82 #define RTM_ADD         0x1     /* Add Route */
83 #define RTM_DELETE      0x2     /* Delete Route */
84 #define RTM_CHANGE      0x3     /* Change Metrics or flags */
85 #define RTM_GET         0x4     /* Report Metrics */
86 #define RTM_LOSING      0x5     /* Kernel Suspects Partitioning */
87 #define RTM_REDIRECT    0x6     /* Told to use different route */
88 #define RTM_MISS        0x7     /* Lookup failed on this address */
89 #define RTM_LOCK        0x8     /* fix specified metrics */
90 #define RTM_OLDADD      0x9     /* caused by SIOCADDRT */
91 #define RTM_OLDDEL      0xa     /* caused by SIOCDELRT */
92 #define RTM_RESOLVE     0xb     /* req to resolve dst to LL addr */
93 #define RTM_NEWADDR     0xc     /* address being added to iface */
94 #define RTM_DELADDR     0xd     /* address being removed from iface */
95 #define RTM_IFINFO      0xe     /* iface going up/down etc. */
96 
97 #define RTV_MTU         0x1     /* init or lock _mtu */
98 #define RTV_HOPCOUNT    0x2     /* init or lock _hopcount */
99 #define RTV_EXPIRE      0x4     /* init or lock _hopcount */
100 #define RTV_RPIPE       0x8     /* init or lock _recvpipe */
101 #define RTV_SPIPE       0x10    /* init or lock _sendpipe */
102 #define RTV_SSTHRESH    0x20    /* init or lock _ssthresh */
103 #define RTV_RTT         0x40    /* init or lock _rtt */
104 #define RTV_RTTVAR      0x80    /* init or lock _rttvar */
105 
106 /*
107  * Bitmask values for rtm_addr.
108  */
109 #define RTA_DST         0x1     /* destination sockaddr present */
110 #define RTA_GATEWAY     0x2     /* gateway sockaddr present */
111 #define RTA_NETMASK     0x4     /* netmask sockaddr present */
112 #define RTA_GENMASK     0x8     /* cloning mask sockaddr present */
113 #define RTA_IFP         0x10    /* interface name sockaddr present */
114 #define RTA_IFA         0x20    /* interface addr sockaddr present */
115 #define RTA_AUTHOR      0x40    /* sockaddr for author of redirect */
116 #define RTA_BRD         0x80    /* for NEWADDR, broadcast or p-p dest addr */
117 
118 /*
119  * Index offsets for sockaddr array for alternate internal encoding.
120  */
121 #define RTAX_DST        0       /* destination sockaddr present */
122 #define RTAX_GATEWAY    1       /* gateway sockaddr present */
123 #define RTAX_NETMASK    2       /* netmask sockaddr present */
124 #define RTAX_GENMASK    3       /* cloning mask sockaddr present */
125 #define RTAX_IFP        4       /* interface name sockaddr present */
126 #define RTAX_IFA        5       /* interface addr sockaddr present */
127 #define RTAX_AUTHOR     6       /* sockaddr for author of redirect */
128 #define RTAX_BRD        7       /* for NEWADDR, broadcast or p-p dest addr */
129 #define RTAX_MAX        8       /* size of array to allocate */
130 
131 struct rt_msghdr {
132 	uint16 rtm_msglen;
133 	uint8 rtm_version;
134 	uint8 rtm_type;
135 
136 	uint16 rtm_index;
137 	int rtm_flags;
138 	int rtm_addrs;
139 	int rtm_seq;
140 	int rtm_errno;
141 	int rtm_use;
142 	uint32 rtm_inits;
143 	struct rt_metrics rtm_rmx;
144 };
145 
146 struct rt_addrinfo {
147         int     rti_addrs;
148         struct  sockaddr *rti_info[RTAX_MAX];
149         int     rti_flags;
150         struct  ifaddr *rti_ifa;
151         struct  ifnet *rti_ifp;
152         struct  rt_msghdr *rti_rtm;
153 };
154 
155 struct route_cb {
156 	int32 ip_count;     /* how many AF_INET structures we have */
157 	int32 any_count;    /* total of all above... */
158 };
159 
160 struct walkarg {
161 	int w_op;
162 	int w_arg;
163 	int w_given;
164 	int w_needed;
165 	int w_tmemsize;
166 	char * w_where;
167 	char * w_tmem;
168 };
169 
170 /*
171  * Routing statistics.
172  */
173 struct  rtstat {
174         int32 rts_badredirect;      /* bogus redirect calls */
175         int32 rts_dynamic;          /* routes created by redirects */
176         int32 rts_newgateway;               /* routes modified by redirects */
177         int32 rts_unreach;          /* lookups which failed */
178         int32 rts_wildcard;         /* lookups satisfied by a wildcard */
179 };
180 
181 #define RTFREE(rt) do { \
182         if ((rt)->rt_refcnt <= 1) \
183                 rtfree(rt); \
184         else \
185                 (rt)->rt_refcnt--; \
186 } while (0)
187 
188 extern struct  rtstat  rtstat;
189 extern struct  radix_node_head *rt_tables[AF_MAX+1];
190 
191 void	route_init(void);
192 
193 int	rtinit (struct ifaddr *, int, int);
194 void	rtalloc (struct route *);
195 struct rtentry *rtalloc1 (struct sockaddr *, int);
196 void	rtfree (struct rtentry *);
197 int	rtrequest (int, struct sockaddr *,
198                         struct sockaddr *, struct sockaddr *, int,
199                         struct rtentry **);
200 void	rt_maskedcopy(struct sockaddr *src,
201                 struct sockaddr *dst,
202                 struct sockaddr *netmask);
203 int	rt_setgate (struct rtentry *, struct sockaddr *,
204                          struct sockaddr *);
205 
206 struct radix_node_head ** get_rt_tables(void);
207 
208 #endif /* NET_ROUTE_H */
209