ip.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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
  9. *
  10. * Authors: Ross Biro
  11. * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12. * Alan Cox, <gw4pts@gw4pts.ampr.org>
  13. *
  14. * Changes:
  15. * Mike McLagan : Routing by source
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License
  19. * as published by the Free Software Foundation; either version
  20. * 2 of the License, or (at your option) any later version.
  21. */
  22. #ifndef _IP_H
  23. #define _IP_H
  24. #include <linux/types.h>
  25. #include <linux/ip.h>
  26. #include <linux/in.h>
  27. #include <linux/skbuff.h>
  28. #include <net/inet_sock.h>
  29. #include <net/route.h>
  30. #include <net/snmp.h>
  31. #include <net/flow.h>
  32. #include <net/flow_dissector.h>
  33. #define IPV4_MAX_PMTU 65535U /* RFC 2675, Section 5.1 */
  34. #define IPV4_MIN_MTU 68 /* RFC 791 */
  35. struct sock;
  36. struct inet_skb_parm {
  37. int iif;
  38. struct ip_options opt; /* Compiled IP options */
  39. u16 flags;
  40. #define IPSKB_FORWARDED BIT(0)
  41. #define IPSKB_XFRM_TUNNEL_SIZE BIT(1)
  42. #define IPSKB_XFRM_TRANSFORMED BIT(2)
  43. #define IPSKB_FRAG_COMPLETE BIT(3)
  44. #define IPSKB_REROUTED BIT(4)
  45. #define IPSKB_DOREDIRECT BIT(5)
  46. #define IPSKB_FRAG_PMTU BIT(6)
  47. #define IPSKB_L3SLAVE BIT(7)
  48. u16 frag_max_size;
  49. };
  50. static inline bool ipv4_l3mdev_skb(u16 flags)
  51. {
  52. return !!(flags & IPSKB_L3SLAVE);
  53. }
  54. static inline unsigned int ip_hdrlen(const struct sk_buff *skb)
  55. {
  56. return ip_hdr(skb)->ihl * 4;
  57. }
  58. struct ipcm_cookie {
  59. struct sockcm_cookie sockc;
  60. __be32 addr;
  61. int oif;
  62. struct ip_options_rcu *opt;
  63. __u8 tx_flags;
  64. __u8 ttl;
  65. __s16 tos;
  66. char priority;
  67. __u16 gso_size;
  68. };
  69. #define IPCB(skb) ((struct inet_skb_parm*)((skb)->cb))
  70. #define PKTINFO_SKB_CB(skb) ((struct in_pktinfo *)((skb)->cb))
  71. /* return enslaved device index if relevant */
  72. static inline int inet_sdif(struct sk_buff *skb)
  73. {
  74. #if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
  75. if (skb && ipv4_l3mdev_skb(IPCB(skb)->flags))
  76. return IPCB(skb)->iif;
  77. #endif
  78. return 0;
  79. }
  80. struct ip_ra_chain {
  81. struct ip_ra_chain __rcu *next;
  82. struct sock *sk;
  83. union {
  84. void (*destructor)(struct sock *);
  85. struct sock *saved_sk;
  86. };
  87. struct rcu_head rcu;
  88. };
  89. extern struct ip_ra_chain __rcu *ip_ra_chain;
  90. /* IP flags. */
  91. #define IP_CE 0x8000 /* Flag: "Congestion" */
  92. #define IP_DF 0x4000 /* Flag: "Don't Fragment" */
  93. #define IP_MF 0x2000 /* Flag: "More Fragments" */
  94. #define IP_OFFSET 0x1FFF /* "Fragment Offset" part */
  95. #define IP_FRAG_TIME (30 * HZ) /* fragment lifetime */
  96. struct msghdr;
  97. struct net_device;
  98. struct packet_type;
  99. struct rtable;
  100. struct sockaddr;
  101. int igmp_mc_init(void);
  102. /*
  103. * Functions provided by ip.c
  104. */
  105. int ip_build_and_send_pkt(struct sk_buff *skb, const struct sock *sk,
  106. __be32 saddr, __be32 daddr,
  107. struct ip_options_rcu *opt);
  108. int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
  109. struct net_device *orig_dev);
  110. void ip_list_rcv(struct list_head *head, struct packet_type *pt,
  111. struct net_device *orig_dev);
  112. int ip_local_deliver(struct sk_buff *skb);
  113. void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int proto);
  114. int ip_mr_input(struct sk_buff *skb);
  115. int ip_output(struct net *net, struct sock *sk, struct sk_buff *skb);
  116. int ip_mc_output(struct net *net, struct sock *sk, struct sk_buff *skb);
  117. int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
  118. int (*output)(struct net *, struct sock *, struct sk_buff *));
  119. void ip_send_check(struct iphdr *ip);
  120. int ip_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
  121. unsigned int mtu,
  122. int (*output)(struct net *, struct sock *, struct sk_buff *));
  123. int __ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb);
  124. int ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb);
  125. int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl);
  126. void ip_init(void);
  127. int ip_append_data(struct sock *sk, struct flowi4 *fl4,
  128. int getfrag(void *from, char *to, int offset, int len,
  129. int odd, struct sk_buff *skb),
  130. void *from, int len, int protolen,
  131. struct ipcm_cookie *ipc,
  132. struct rtable **rt,
  133. unsigned int flags);
  134. int ip_generic_getfrag(void *from, char *to, int offset, int len, int odd,
  135. struct sk_buff *skb);
  136. ssize_t ip_append_page(struct sock *sk, struct flowi4 *fl4, struct page *page,
  137. int offset, size_t size, int flags);
  138. struct sk_buff *__ip_make_skb(struct sock *sk, struct flowi4 *fl4,
  139. struct sk_buff_head *queue,
  140. struct inet_cork *cork);
  141. int ip_send_skb(struct net *net, struct sk_buff *skb);
  142. int ip_push_pending_frames(struct sock *sk, struct flowi4 *fl4);
  143. void ip_flush_pending_frames(struct sock *sk);
  144. struct sk_buff *ip_make_skb(struct sock *sk, struct flowi4 *fl4,
  145. int getfrag(void *from, char *to, int offset,
  146. int len, int odd, struct sk_buff *skb),
  147. void *from, int length, int transhdrlen,
  148. struct ipcm_cookie *ipc, struct rtable **rtp,
  149. struct inet_cork *cork, unsigned int flags);
  150. static inline struct sk_buff *ip_finish_skb(struct sock *sk, struct flowi4 *fl4)
  151. {
  152. return __ip_make_skb(sk, fl4, &sk->sk_write_queue, &inet_sk(sk)->cork.base);
  153. }
  154. static inline __u8 get_rttos(struct ipcm_cookie* ipc, struct inet_sock *inet)
  155. {
  156. return (ipc->tos != -1) ? RT_TOS(ipc->tos) : RT_TOS(inet->tos);
  157. }
  158. static inline __u8 get_rtconn_flags(struct ipcm_cookie* ipc, struct sock* sk)
  159. {
  160. return (ipc->tos != -1) ? RT_CONN_FLAGS_TOS(sk, ipc->tos) : RT_CONN_FLAGS(sk);
  161. }
  162. /* datagram.c */
  163. int __ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
  164. int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
  165. void ip4_datagram_release_cb(struct sock *sk);
  166. struct ip_reply_arg {
  167. struct kvec iov[1];
  168. int flags;
  169. __wsum csum;
  170. int csumoffset; /* u16 offset of csum in iov[0].iov_base */
  171. /* -1 if not needed */
  172. int bound_dev_if;
  173. u8 tos;
  174. kuid_t uid;
  175. };
  176. #define IP_REPLY_ARG_NOSRCCHECK 1
  177. static inline __u8 ip_reply_arg_flowi_flags(const struct ip_reply_arg *arg)
  178. {
  179. return (arg->flags & IP_REPLY_ARG_NOSRCCHECK) ? FLOWI_FLAG_ANYSRC : 0;
  180. }
  181. void ip_send_unicast_reply(struct sock *sk, struct sk_buff *skb,
  182. const struct ip_options *sopt,
  183. __be32 daddr, __be32 saddr,
  184. const struct ip_reply_arg *arg,
  185. unsigned int len);
  186. #define IP_INC_STATS(net, field) SNMP_INC_STATS64((net)->mib.ip_statistics, field)
  187. #define __IP_INC_STATS(net, field) __SNMP_INC_STATS64((net)->mib.ip_statistics, field)
  188. #define IP_ADD_STATS(net, field, val) SNMP_ADD_STATS64((net)->mib.ip_statistics, field, val)
  189. #define __IP_ADD_STATS(net, field, val) __SNMP_ADD_STATS64((net)->mib.ip_statistics, field, val)
  190. #define IP_UPD_PO_STATS(net, field, val) SNMP_UPD_PO_STATS64((net)->mib.ip_statistics, field, val)
  191. #define __IP_UPD_PO_STATS(net, field, val) __SNMP_UPD_PO_STATS64((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(net, field) __SNMP_INC_STATS((net)->mib.net_statistics, field)
  194. #define NET_ADD_STATS(net, field, adnd) SNMP_ADD_STATS((net)->mib.net_statistics, field, adnd)
  195. #define __NET_ADD_STATS(net, field, adnd) __SNMP_ADD_STATS((net)->mib.net_statistics, field, adnd)
  196. u64 snmp_get_cpu_field(void __percpu *mib, int cpu, int offct);
  197. unsigned long snmp_fold_field(void __percpu *mib, int offt);
  198. #if BITS_PER_LONG==32
  199. u64 snmp_get_cpu_field64(void __percpu *mib, int cpu, int offct,
  200. size_t syncp_offset);
  201. u64 snmp_fold_field64(void __percpu *mib, int offt, size_t sync_off);
  202. #else
  203. static inline u64 snmp_get_cpu_field64(void __percpu *mib, int cpu, int offct,
  204. size_t syncp_offset)
  205. {
  206. return snmp_get_cpu_field(mib, cpu, offct);
  207. }
  208. static inline u64 snmp_fold_field64(void __percpu *mib, int offt, size_t syncp_off)
  209. {
  210. return snmp_fold_field(mib, offt);
  211. }
  212. #endif
  213. #define snmp_get_cpu_field64_batch(buff64, stats_list, mib_statistic, offset) \
  214. { \
  215. int i, c; \
  216. for_each_possible_cpu(c) { \
  217. for (i = 0; stats_list[i].name; i++) \
  218. buff64[i] += snmp_get_cpu_field64( \
  219. mib_statistic, \
  220. c, stats_list[i].entry, \
  221. offset); \
  222. } \
  223. }
  224. #define snmp_get_cpu_field_batch(buff, stats_list, mib_statistic) \
  225. { \
  226. int i, c; \
  227. for_each_possible_cpu(c) { \
  228. for (i = 0; stats_list[i].name; i++) \
  229. buff[i] += snmp_get_cpu_field( \
  230. mib_statistic, \
  231. c, stats_list[i].entry); \
  232. } \
  233. }
  234. void inet_get_local_port_range(struct net *net, int *low, int *high);
  235. #ifdef CONFIG_SYSCTL
  236. static inline int inet_is_local_reserved_port(struct net *net, int port)
  237. {
  238. if (!net->ipv4.sysctl_local_reserved_ports)
  239. return 0;
  240. return test_bit(port, net->ipv4.sysctl_local_reserved_ports);
  241. }
  242. static inline bool sysctl_dev_name_is_allowed(const char *name)
  243. {
  244. return strcmp(name, "default") != 0 && strcmp(name, "all") != 0;
  245. }
  246. static inline int inet_prot_sock(struct net *net)
  247. {
  248. return net->ipv4.sysctl_ip_prot_sock;
  249. }
  250. #else
  251. static inline int inet_is_local_reserved_port(struct net *net, int port)
  252. {
  253. return 0;
  254. }
  255. static inline int inet_prot_sock(struct net *net)
  256. {
  257. return PROT_SOCK;
  258. }
  259. #endif
  260. __be32 inet_current_timestamp(void);
  261. /* From inetpeer.c */
  262. extern int inet_peer_threshold;
  263. extern int inet_peer_minttl;
  264. extern int inet_peer_maxttl;
  265. void ipfrag_init(void);
  266. void ip_static_sysctl_init(void);
  267. #define IP4_REPLY_MARK(net, mark) \
  268. ((net)->ipv4.sysctl_fwmark_reflect ? (mark) : 0)
  269. static inline bool ip_is_fragment(const struct iphdr *iph)
  270. {
  271. return (iph->frag_off & htons(IP_MF | IP_OFFSET)) != 0;
  272. }
  273. #ifdef CONFIG_INET
  274. #include <net/dst.h>
  275. /* The function in 2.2 was invalid, producing wrong result for
  276. * check=0xFEFF. It was noticed by Arthur Skawina _year_ ago. --ANK(000625) */
  277. static inline
  278. int ip_decrease_ttl(struct iphdr *iph)
  279. {
  280. u32 check = (__force u32)iph->check;
  281. check += (__force u32)htons(0x0100);
  282. iph->check = (__force __sum16)(check + (check>=0xFFFF));
  283. return --iph->ttl;
  284. }
  285. static inline int ip_mtu_locked(const struct dst_entry *dst)
  286. {
  287. const struct rtable *rt = (const struct rtable *)dst;
  288. return rt->rt_mtu_locked || dst_metric_locked(dst, RTAX_MTU);
  289. }
  290. static inline
  291. int ip_dont_fragment(const struct sock *sk, const struct dst_entry *dst)
  292. {
  293. u8 pmtudisc = READ_ONCE(inet_sk(sk)->pmtudisc);
  294. return pmtudisc == IP_PMTUDISC_DO ||
  295. (pmtudisc == IP_PMTUDISC_WANT &&
  296. !ip_mtu_locked(dst));
  297. }
  298. static inline bool ip_sk_accept_pmtu(const struct sock *sk)
  299. {
  300. return inet_sk(sk)->pmtudisc != IP_PMTUDISC_INTERFACE &&
  301. inet_sk(sk)->pmtudisc != IP_PMTUDISC_OMIT;
  302. }
  303. static inline bool ip_sk_use_pmtu(const struct sock *sk)
  304. {
  305. return inet_sk(sk)->pmtudisc < IP_PMTUDISC_PROBE;
  306. }
  307. static inline bool ip_sk_ignore_df(const struct sock *sk)
  308. {
  309. return inet_sk(sk)->pmtudisc < IP_PMTUDISC_DO ||
  310. inet_sk(sk)->pmtudisc == IP_PMTUDISC_OMIT;
  311. }
  312. static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
  313. bool forwarding)
  314. {
  315. struct net *net = dev_net(dst->dev);
  316. unsigned int mtu;
  317. if (net->ipv4.sysctl_ip_fwd_use_pmtu ||
  318. ip_mtu_locked(dst) ||
  319. !forwarding)
  320. return dst_mtu(dst);
  321. /* 'forwarding = true' case should always honour route mtu */
  322. mtu = dst_metric_raw(dst, RTAX_MTU);
  323. if (mtu)
  324. return mtu;
  325. return min(READ_ONCE(dst->dev->mtu), IP_MAX_MTU);
  326. }
  327. static inline unsigned int ip_skb_dst_mtu(struct sock *sk,
  328. const struct sk_buff *skb)
  329. {
  330. if (!sk || !sk_fullsock(sk) || ip_sk_use_pmtu(sk)) {
  331. bool forwarding = IPCB(skb)->flags & IPSKB_FORWARDED;
  332. return ip_dst_mtu_maybe_forward(skb_dst(skb), forwarding);
  333. }
  334. return min(READ_ONCE(skb_dst(skb)->dev->mtu), IP_MAX_MTU);
  335. }
  336. u32 ip_idents_reserve(u32 hash, int segs);
  337. void __ip_select_ident(struct net *net, struct iphdr *iph, int segs);
  338. static inline void ip_select_ident_segs(struct net *net, struct sk_buff *skb,
  339. struct sock *sk, int segs)
  340. {
  341. struct iphdr *iph = ip_hdr(skb);
  342. if ((iph->frag_off & htons(IP_DF)) && !skb->ignore_df) {
  343. /* This is only to work around buggy Windows95/2000
  344. * VJ compression implementations. If the ID field
  345. * does not change, they drop every other packet in
  346. * a TCP stream using header compression.
  347. */
  348. if (sk && inet_sk(sk)->inet_daddr) {
  349. iph->id = htons(inet_sk(sk)->inet_id);
  350. inet_sk(sk)->inet_id += segs;
  351. } else {
  352. iph->id = 0;
  353. }
  354. } else {
  355. __ip_select_ident(net, iph, segs);
  356. }
  357. }
  358. static inline void ip_select_ident(struct net *net, struct sk_buff *skb,
  359. struct sock *sk)
  360. {
  361. ip_select_ident_segs(net, skb, sk, 1);
  362. }
  363. static inline __wsum inet_compute_pseudo(struct sk_buff *skb, int proto)
  364. {
  365. return csum_tcpudp_nofold(ip_hdr(skb)->saddr, ip_hdr(skb)->daddr,
  366. skb->len, proto, 0);
  367. }
  368. /* copy IPv4 saddr & daddr to flow_keys, possibly using 64bit load/store
  369. * Equivalent to : flow->v4addrs.src = iph->saddr;
  370. * flow->v4addrs.dst = iph->daddr;
  371. */
  372. static inline void iph_to_flow_copy_v4addrs(struct flow_keys *flow,
  373. const struct iphdr *iph)
  374. {
  375. BUILD_BUG_ON(offsetof(typeof(flow->addrs), v4addrs.dst) !=
  376. offsetof(typeof(flow->addrs), v4addrs.src) +
  377. sizeof(flow->addrs.v4addrs.src));
  378. memcpy(&flow->addrs.v4addrs, &iph->saddr, sizeof(flow->addrs.v4addrs));
  379. flow->control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
  380. }
  381. static inline __wsum inet_gro_compute_pseudo(struct sk_buff *skb, int proto)
  382. {
  383. const struct iphdr *iph = skb_gro_network_header(skb);
  384. return csum_tcpudp_nofold(iph->saddr, iph->daddr,
  385. skb_gro_len(skb), proto, 0);
  386. }
  387. /*
  388. * Map a multicast IP onto multicast MAC for type ethernet.
  389. */
  390. static inline void ip_eth_mc_map(__be32 naddr, char *buf)
  391. {
  392. __u32 addr=ntohl(naddr);
  393. buf[0]=0x01;
  394. buf[1]=0x00;
  395. buf[2]=0x5e;
  396. buf[5]=addr&0xFF;
  397. addr>>=8;
  398. buf[4]=addr&0xFF;
  399. addr>>=8;
  400. buf[3]=addr&0x7F;
  401. }
  402. /*
  403. * Map a multicast IP onto multicast MAC for type IP-over-InfiniBand.
  404. * Leave P_Key as 0 to be filled in by driver.
  405. */
  406. static inline void ip_ib_mc_map(__be32 naddr, const unsigned char *broadcast, char *buf)
  407. {
  408. __u32 addr;
  409. unsigned char scope = broadcast[5] & 0xF;
  410. buf[0] = 0; /* Reserved */
  411. buf[1] = 0xff; /* Multicast QPN */
  412. buf[2] = 0xff;
  413. buf[3] = 0xff;
  414. addr = ntohl(naddr);
  415. buf[4] = 0xff;
  416. buf[5] = 0x10 | scope; /* scope from broadcast address */
  417. buf[6] = 0x40; /* IPv4 signature */
  418. buf[7] = 0x1b;
  419. buf[8] = broadcast[8]; /* P_Key */
  420. buf[9] = broadcast[9];
  421. buf[10] = 0;
  422. buf[11] = 0;
  423. buf[12] = 0;
  424. buf[13] = 0;
  425. buf[14] = 0;
  426. buf[15] = 0;
  427. buf[19] = addr & 0xff;
  428. addr >>= 8;
  429. buf[18] = addr & 0xff;
  430. addr >>= 8;
  431. buf[17] = addr & 0xff;
  432. addr >>= 8;
  433. buf[16] = addr & 0x0f;
  434. }
  435. static inline void ip_ipgre_mc_map(__be32 naddr, const unsigned char *broadcast, char *buf)
  436. {
  437. if ((broadcast[0] | broadcast[1] | broadcast[2] | broadcast[3]) != 0)
  438. memcpy(buf, broadcast, 4);
  439. else
  440. memcpy(buf, &naddr, sizeof(naddr));
  441. }
  442. #if IS_ENABLED(CONFIG_IPV6)
  443. #include <linux/ipv6.h>
  444. #endif
  445. static __inline__ void inet_reset_saddr(struct sock *sk)
  446. {
  447. inet_sk(sk)->inet_rcv_saddr = inet_sk(sk)->inet_saddr = 0;
  448. #if IS_ENABLED(CONFIG_IPV6)
  449. if (sk->sk_family == PF_INET6) {
  450. struct ipv6_pinfo *np = inet6_sk(sk);
  451. memset(&np->saddr, 0, sizeof(np->saddr));
  452. memset(&sk->sk_v6_rcv_saddr, 0, sizeof(sk->sk_v6_rcv_saddr));
  453. }
  454. #endif
  455. }
  456. #endif
  457. static inline unsigned int ipv4_addr_hash(__be32 ip)
  458. {
  459. return (__force unsigned int) ip;
  460. }
  461. bool ip_call_ra_chain(struct sk_buff *skb);
  462. /*
  463. * Functions provided by ip_fragment.c
  464. */
  465. enum ip_defrag_users {
  466. IP_DEFRAG_LOCAL_DELIVER,
  467. IP_DEFRAG_CALL_RA_CHAIN,
  468. IP_DEFRAG_CONNTRACK_IN,
  469. __IP_DEFRAG_CONNTRACK_IN_END = IP_DEFRAG_CONNTRACK_IN + USHRT_MAX,
  470. IP_DEFRAG_CONNTRACK_OUT,
  471. __IP_DEFRAG_CONNTRACK_OUT_END = IP_DEFRAG_CONNTRACK_OUT + USHRT_MAX,
  472. IP_DEFRAG_CONNTRACK_BRIDGE_IN,
  473. __IP_DEFRAG_CONNTRACK_BRIDGE_IN = IP_DEFRAG_CONNTRACK_BRIDGE_IN + USHRT_MAX,
  474. IP_DEFRAG_VS_IN,
  475. IP_DEFRAG_VS_OUT,
  476. IP_DEFRAG_VS_FWD,
  477. IP_DEFRAG_AF_PACKET,
  478. IP_DEFRAG_MACVLAN,
  479. };
  480. /* Return true if the value of 'user' is between 'lower_bond'
  481. * and 'upper_bond' inclusively.
  482. */
  483. static inline bool ip_defrag_user_in_between(u32 user,
  484. enum ip_defrag_users lower_bond,
  485. enum ip_defrag_users upper_bond)
  486. {
  487. return user >= lower_bond && user <= upper_bond;
  488. }
  489. int ip_defrag(struct net *net, struct sk_buff *skb, u32 user);
  490. #ifdef CONFIG_INET
  491. struct sk_buff *ip_check_defrag(struct net *net, struct sk_buff *skb, u32 user);
  492. #else
  493. static inline struct sk_buff *ip_check_defrag(struct net *net, struct sk_buff *skb, u32 user)
  494. {
  495. return skb;
  496. }
  497. #endif
  498. /*
  499. * Functions provided by ip_forward.c
  500. */
  501. int ip_forward(struct sk_buff *skb);
  502. /*
  503. * Functions provided by ip_options.c
  504. */
  505. void ip_options_build(struct sk_buff *skb, struct ip_options *opt,
  506. __be32 daddr, struct rtable *rt, int is_frag);
  507. int __ip_options_echo(struct net *net, struct ip_options *dopt,
  508. struct sk_buff *skb, const struct ip_options *sopt);
  509. static inline int ip_options_echo(struct net *net, struct ip_options *dopt,
  510. struct sk_buff *skb)
  511. {
  512. return __ip_options_echo(net, dopt, skb, &IPCB(skb)->opt);
  513. }
  514. void ip_options_fragment(struct sk_buff *skb);
  515. int __ip_options_compile(struct net *net, struct ip_options *opt,
  516. struct sk_buff *skb, __be32 *info);
  517. int ip_options_compile(struct net *net, struct ip_options *opt,
  518. struct sk_buff *skb);
  519. int ip_options_get(struct net *net, struct ip_options_rcu **optp,
  520. unsigned char *data, int optlen);
  521. int ip_options_get_from_user(struct net *net, struct ip_options_rcu **optp,
  522. unsigned char __user *data, int optlen);
  523. void ip_options_undo(struct ip_options *opt);
  524. void ip_forward_options(struct sk_buff *skb);
  525. int ip_options_rcv_srr(struct sk_buff *skb, struct net_device *dev);
  526. /*
  527. * Functions provided by ip_sockglue.c
  528. */
  529. void ipv4_pktinfo_prepare(const struct sock *sk, struct sk_buff *skb);
  530. void ip_cmsg_recv_offset(struct msghdr *msg, struct sock *sk,
  531. struct sk_buff *skb, int tlen, int offset);
  532. int ip_cmsg_send(struct sock *sk, struct msghdr *msg,
  533. struct ipcm_cookie *ipc, bool allow_ipv6);
  534. int ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval,
  535. unsigned int optlen);
  536. int ip_getsockopt(struct sock *sk, int level, int optname, char __user *optval,
  537. int __user *optlen);
  538. int compat_ip_setsockopt(struct sock *sk, int level, int optname,
  539. char __user *optval, unsigned int optlen);
  540. int compat_ip_getsockopt(struct sock *sk, int level, int optname,
  541. char __user *optval, int __user *optlen);
  542. int ip_ra_control(struct sock *sk, unsigned char on,
  543. void (*destructor)(struct sock *));
  544. int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len);
  545. void ip_icmp_error(struct sock *sk, struct sk_buff *skb, int err, __be16 port,
  546. u32 info, u8 *payload);
  547. void ip_local_error(struct sock *sk, int err, __be32 daddr, __be16 dport,
  548. u32 info);
  549. static inline void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb)
  550. {
  551. ip_cmsg_recv_offset(msg, skb->sk, skb, 0, 0);
  552. }
  553. bool icmp_global_allow(void);
  554. extern int sysctl_icmp_msgs_per_sec;
  555. extern int sysctl_icmp_msgs_burst;
  556. #ifdef CONFIG_PROC_FS
  557. int ip_misc_proc_init(void);
  558. #endif
  559. static inline bool inetdev_valid_mtu(unsigned int mtu)
  560. {
  561. return likely(mtu >= IPV4_MIN_MTU);
  562. }
  563. #endif /* _IP_H */