output_core.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * IPv6 library code, needed by static components when full IPv6 support is
  3. * not configured or static. These functions are needed by GSO/GRO implementation.
  4. */
  5. #include <linux/export.h>
  6. #include <net/ipv6.h>
  7. #include <net/ip6_fib.h>
  8. #include <net/addrconf.h>
  9. #include <net/secure_seq.h>
  10. void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
  11. {
  12. static atomic_t ipv6_fragmentation_id;
  13. struct in6_addr addr;
  14. int old, new;
  15. #if IS_ENABLED(CONFIG_IPV6)
  16. struct inet_peer *peer;
  17. struct net *net;
  18. net = dev_net(rt->dst.dev);
  19. peer = inet_getpeer_v6(net->ipv6.peers, &rt->rt6i_dst.addr, 1);
  20. if (peer) {
  21. fhdr->identification = htonl(inet_getid(peer, 0));
  22. inet_putpeer(peer);
  23. return;
  24. }
  25. #endif
  26. do {
  27. old = atomic_read(&ipv6_fragmentation_id);
  28. new = old + 1;
  29. if (!new)
  30. new = 1;
  31. } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
  32. addr = rt->rt6i_dst.addr;
  33. addr.s6_addr32[0] ^= (__force __be32)new;
  34. fhdr->identification = htonl(secure_ipv6_id(addr.s6_addr32));
  35. }
  36. EXPORT_SYMBOL(ipv6_select_ident);
  37. int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
  38. {
  39. u16 offset = sizeof(struct ipv6hdr);
  40. struct ipv6_opt_hdr *exthdr =
  41. (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1);
  42. unsigned int packet_len = skb_tail_pointer(skb) -
  43. skb_network_header(skb);
  44. int found_rhdr = 0;
  45. *nexthdr = &ipv6_hdr(skb)->nexthdr;
  46. while (offset + 1 <= packet_len) {
  47. switch (**nexthdr) {
  48. case NEXTHDR_HOP:
  49. break;
  50. case NEXTHDR_ROUTING:
  51. found_rhdr = 1;
  52. break;
  53. case NEXTHDR_DEST:
  54. #if IS_ENABLED(CONFIG_IPV6_MIP6)
  55. if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0)
  56. break;
  57. #endif
  58. if (found_rhdr)
  59. return offset;
  60. break;
  61. default :
  62. return offset;
  63. }
  64. offset += ipv6_optlen(exthdr);
  65. *nexthdr = &exthdr->nexthdr;
  66. exthdr = (struct ipv6_opt_hdr *)(skb_network_header(skb) +
  67. offset);
  68. }
  69. return offset;
  70. }
  71. EXPORT_SYMBOL(ip6_find_1stfragopt);
  72. #if IS_ENABLED(CONFIG_IPV6)
  73. int ip6_dst_hoplimit(struct dst_entry *dst)
  74. {
  75. int hoplimit = dst_metric_raw(dst, RTAX_HOPLIMIT);
  76. if (hoplimit == 0) {
  77. struct net_device *dev = dst->dev;
  78. struct inet6_dev *idev;
  79. rcu_read_lock();
  80. idev = __in6_dev_get(dev);
  81. if (idev)
  82. hoplimit = idev->cnf.hop_limit;
  83. else
  84. hoplimit = dev_net(dev)->ipv6.devconf_all->hop_limit;
  85. rcu_read_unlock();
  86. }
  87. return hoplimit;
  88. }
  89. EXPORT_SYMBOL(ip6_dst_hoplimit);
  90. #endif
  91. int __ip6_local_out(struct sk_buff *skb)
  92. {
  93. int len;
  94. len = skb->len - sizeof(struct ipv6hdr);
  95. if (len > IPV6_MAXPLEN)
  96. len = 0;
  97. ipv6_hdr(skb)->payload_len = htons(len);
  98. return nf_hook(NFPROTO_IPV6, NF_INET_LOCAL_OUT, skb, NULL,
  99. skb_dst(skb)->dev, dst_output);
  100. }
  101. EXPORT_SYMBOL_GPL(__ip6_local_out);
  102. int ip6_local_out(struct sk_buff *skb)
  103. {
  104. int err;
  105. err = __ip6_local_out(skb);
  106. if (likely(err == 1))
  107. err = dst_output(skb);
  108. return err;
  109. }
  110. EXPORT_SYMBOL_GPL(ip6_local_out);