ip.h (c0981b863a31a1891aa2719957983f4297770f87) ip.h (73f156a6e8c1074ac6327e0abd1169e95eb66463)
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Definitions for the IP module.
7 *
8 * Version: @(#)ip.h 1.0.2 05/07/93

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

191#define IP_UPD_PO_STATS_BH(net, field, val) SNMP_UPD_PO_STATS64_BH((net)->mib.ip_statistics, field, val)
192#define NET_INC_STATS(net, field) SNMP_INC_STATS((net)->mib.net_statistics, field)
193#define NET_INC_STATS_BH(net, field) SNMP_INC_STATS_BH((net)->mib.net_statistics, field)
194#define NET_INC_STATS_USER(net, field) SNMP_INC_STATS_USER((net)->mib.net_statistics, field)
195#define NET_ADD_STATS(net, field, adnd) SNMP_ADD_STATS((net)->mib.net_statistics, field, adnd)
196#define NET_ADD_STATS_BH(net, field, adnd) SNMP_ADD_STATS_BH((net)->mib.net_statistics, field, adnd)
197#define NET_ADD_STATS_USER(net, field, adnd) SNMP_ADD_STATS_USER((net)->mib.net_statistics, field, adnd)
198
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Definitions for the IP module.
7 *
8 * Version: @(#)ip.h 1.0.2 05/07/93

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

191#define IP_UPD_PO_STATS_BH(net, field, val) SNMP_UPD_PO_STATS64_BH((net)->mib.ip_statistics, field, val)
192#define NET_INC_STATS(net, field) SNMP_INC_STATS((net)->mib.net_statistics, field)
193#define NET_INC_STATS_BH(net, field) SNMP_INC_STATS_BH((net)->mib.net_statistics, field)
194#define NET_INC_STATS_USER(net, field) SNMP_INC_STATS_USER((net)->mib.net_statistics, field)
195#define NET_ADD_STATS(net, field, adnd) SNMP_ADD_STATS((net)->mib.net_statistics, field, adnd)
196#define NET_ADD_STATS_BH(net, field, adnd) SNMP_ADD_STATS_BH((net)->mib.net_statistics, field, adnd)
197#define NET_ADD_STATS_USER(net, field, adnd) SNMP_ADD_STATS_USER((net)->mib.net_statistics, field, adnd)
198
199unsigned long snmp_fold_field(void __percpu *mib[], int offt);
199unsigned long snmp_fold_field(void __percpu *mib, int offt);
200#if BITS_PER_LONG==32
200#if BITS_PER_LONG==32
201u64 snmp_fold_field64(void __percpu *mib[], int offt, size_t sync_off);
201u64 snmp_fold_field64(void __percpu *mib, int offt, size_t sync_off);
202#else
202#else
203static inline u64 snmp_fold_field64(void __percpu *mib[], int offt, size_t syncp_off)
203static inline u64 snmp_fold_field64(void __percpu *mib, int offt, size_t syncp_off)
204{
205 return snmp_fold_field(mib, offt);
206}
207#endif
204{
205 return snmp_fold_field(mib, offt);
206}
207#endif
208int snmp_mib_init(void __percpu *ptr[2], size_t mibsize, size_t align);
209
208
210static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
211{
212 int i;
213
214 BUG_ON(ptr == NULL);
215 for (i = 0; i < SNMP_ARRAY_SZ; i++) {
216 free_percpu(ptr[i]);
217 ptr[i] = NULL;
218 }
219}
220
221void inet_get_local_port_range(struct net *net, int *low, int *high);
222
209void inet_get_local_port_range(struct net *net, int *low, int *high);
210
223extern unsigned long *sysctl_local_reserved_ports;
224static inline int inet_is_reserved_local_port(int port)
211#ifdef CONFIG_SYSCTL
212static inline int inet_is_local_reserved_port(struct net *net, int port)
225{
213{
226 return test_bit(port, sysctl_local_reserved_ports);
214 if (!net->ipv4.sysctl_local_reserved_ports)
215 return 0;
216 return test_bit(port, net->ipv4.sysctl_local_reserved_ports);
227}
217}
218#else
219static inline int inet_is_local_reserved_port(struct net *net, int port)
220{
221 return 0;
222}
223#endif
228
229extern int sysctl_ip_nonlocal_bind;
230
231/* From inetpeer.c */
232extern int inet_peer_threshold;
233extern int inet_peer_minttl;
234extern int inet_peer_maxttl;
235
236/* From ip_input.c */
237extern int sysctl_ip_early_demux;
238
239/* From ip_output.c */
240extern int sysctl_ip_dynaddr;
241
242void ipfrag_init(void);
243
244void ip_static_sysctl_init(void);
245
224
225extern int sysctl_ip_nonlocal_bind;
226
227/* From inetpeer.c */
228extern int inet_peer_threshold;
229extern int inet_peer_minttl;
230extern int inet_peer_maxttl;
231
232/* From ip_input.c */
233extern int sysctl_ip_early_demux;
234
235/* From ip_output.c */
236extern int sysctl_ip_dynaddr;
237
238void ipfrag_init(void);
239
240void ip_static_sysctl_init(void);
241
242#define IP4_REPLY_MARK(net, mark) \
243 ((net)->ipv4.sysctl_fwmark_reflect ? (mark) : 0)
244
246static inline bool ip_is_fragment(const struct iphdr *iph)
247{
248 return (iph->frag_off & htons(IP_MF | IP_OFFSET)) != 0;
249}
250
251#ifdef CONFIG_INET
252#include <net/dst.h>
253

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

276 inet_sk(sk)->pmtudisc != IP_PMTUDISC_OMIT;
277}
278
279static inline bool ip_sk_use_pmtu(const struct sock *sk)
280{
281 return inet_sk(sk)->pmtudisc < IP_PMTUDISC_PROBE;
282}
283
245static inline bool ip_is_fragment(const struct iphdr *iph)
246{
247 return (iph->frag_off & htons(IP_MF | IP_OFFSET)) != 0;
248}
249
250#ifdef CONFIG_INET
251#include <net/dst.h>
252

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

275 inet_sk(sk)->pmtudisc != IP_PMTUDISC_OMIT;
276}
277
278static inline bool ip_sk_use_pmtu(const struct sock *sk)
279{
280 return inet_sk(sk)->pmtudisc < IP_PMTUDISC_PROBE;
281}
282
284static inline bool ip_sk_local_df(const struct sock *sk)
283static inline bool ip_sk_ignore_df(const struct sock *sk)
285{
286 return inet_sk(sk)->pmtudisc < IP_PMTUDISC_DO ||
287 inet_sk(sk)->pmtudisc == IP_PMTUDISC_OMIT;
288}
289
290static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
291 bool forwarding)
292{

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

305 if (!skb->sk || ip_sk_use_pmtu(skb->sk)) {
306 bool forwarding = IPCB(skb)->flags & IPSKB_FORWARDED;
307 return ip_dst_mtu_maybe_forward(skb_dst(skb), forwarding);
308 } else {
309 return min(skb_dst(skb)->dev->mtu, IP_MAX_MTU);
310 }
311}
312
284{
285 return inet_sk(sk)->pmtudisc < IP_PMTUDISC_DO ||
286 inet_sk(sk)->pmtudisc == IP_PMTUDISC_OMIT;
287}
288
289static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
290 bool forwarding)
291{

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

304 if (!skb->sk || ip_sk_use_pmtu(skb->sk)) {
305 bool forwarding = IPCB(skb)->flags & IPSKB_FORWARDED;
306 return ip_dst_mtu_maybe_forward(skb_dst(skb), forwarding);
307 } else {
308 return min(skb_dst(skb)->dev->mtu, IP_MAX_MTU);
309 }
310}
311
313void __ip_select_ident(struct iphdr *iph, struct dst_entry *dst, int more);
312#define IP_IDENTS_SZ 2048u
313extern atomic_t *ip_idents;
314
314
315static inline void ip_select_ident(struct sk_buff *skb, struct dst_entry *dst, struct sock *sk)
315static inline u32 ip_idents_reserve(u32 hash, int segs)
316{
316{
317 atomic_t *id_ptr = ip_idents + hash % IP_IDENTS_SZ;
318
319 return atomic_add_return(segs, id_ptr) - segs;
320}
321
322void __ip_select_ident(struct iphdr *iph, int segs);
323
324static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
325{
317 struct iphdr *iph = ip_hdr(skb);
318
326 struct iphdr *iph = ip_hdr(skb);
327
319 if ((iph->frag_off & htons(IP_DF)) && !skb->local_df) {
328 if ((iph->frag_off & htons(IP_DF)) && !skb->ignore_df) {
320 /* This is only to work around buggy Windows95/2000
321 * VJ compression implementations. If the ID field
322 * does not change, they drop every other packet in
323 * a TCP stream using header compression.
324 */
329 /* This is only to work around buggy Windows95/2000
330 * VJ compression implementations. If the ID field
331 * does not change, they drop every other packet in
332 * a TCP stream using header compression.
333 */
325 iph->id = (sk && inet_sk(sk)->inet_daddr) ?
326 htons(inet_sk(sk)->inet_id++) : 0;
327 } else
328 __ip_select_ident(iph, dst, 0);
334 if (sk && inet_sk(sk)->inet_daddr) {
335 iph->id = htons(inet_sk(sk)->inet_id);
336 inet_sk(sk)->inet_id += segs;
337 } else {
338 iph->id = 0;
339 }
340 } else {
341 __ip_select_ident(iph, segs);
342 }
329}
330
343}
344
331static inline void ip_select_ident_more(struct sk_buff *skb, struct dst_entry *dst, struct sock *sk, int more)
345static inline void ip_select_ident(struct sk_buff *skb, struct sock *sk)
332{
346{
333 struct iphdr *iph = ip_hdr(skb);
347 ip_select_ident_segs(skb, sk, 1);
348}
334
349
335 if ((iph->frag_off & htons(IP_DF)) && !skb->local_df) {
336 if (sk && inet_sk(sk)->inet_daddr) {
337 iph->id = htons(inet_sk(sk)->inet_id);
338 inet_sk(sk)->inet_id += 1 + more;
339 } else
340 iph->id = 0;
341 } else
342 __ip_select_ident(iph, dst, more);
350static inline __wsum inet_compute_pseudo(struct sk_buff *skb, int proto)
351{
352 return csum_tcpudp_nofold(ip_hdr(skb)->saddr, ip_hdr(skb)->daddr,
353 skb->len, proto, 0);
343}
344
345/*
346 * Map a multicast IP onto multicast MAC for type ethernet.
347 */
348
349static inline void ip_eth_mc_map(__be32 naddr, char *buf)
350{

--- 178 unchanged lines hidden ---
354}
355
356/*
357 * Map a multicast IP onto multicast MAC for type ethernet.
358 */
359
360static inline void ip_eth_mc_map(__be32 naddr, char *buf)
361{

--- 178 unchanged lines hidden ---