ip.h 17 KB

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