output_core.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
  10. {
  11. static atomic_t ipv6_fragmentation_id;
  12. int old, new;
  13. #if IS_ENABLED(CONFIG_IPV6)
  14. if (rt && !(rt->dst.flags & DST_NOPEER)) {
  15. struct inet_peer *peer;
  16. struct net *net;
  17. net = dev_net(rt->dst.dev);
  18. peer = inet_getpeer_v6(net->ipv6.peers, &rt->rt6i_dst.addr, 1);
  19. if (peer) {
  20. fhdr->identification = htonl(inet_getid(peer, 0));
  21. inet_putpeer(peer);
  22. return;
  23. }
  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. fhdr->identification = htonl(new);
  33. }
  34. EXPORT_SYMBOL(ipv6_select_ident);
  35. int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
  36. {
  37. u16 offset = sizeof(struct ipv6hdr);
  38. struct ipv6_opt_hdr *exthdr =
  39. (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1);
  40. unsigned int packet_len = skb_tail_pointer(skb) -
  41. skb_network_header(skb);
  42. int found_rhdr = 0;
  43. *nexthdr = &ipv6_hdr(skb)->nexthdr;
  44. while (offset + 1 <= packet_len) {
  45. switch (**nexthdr) {
  46. case NEXTHDR_HOP:
  47. break;
  48. case NEXTHDR_ROUTING:
  49. found_rhdr = 1;
  50. break;
  51. case NEXTHDR_DEST:
  52. #if IS_ENABLED(CONFIG_IPV6_MIP6)
  53. if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0)
  54. break;
  55. #endif
  56. if (found_rhdr)
  57. return offset;
  58. break;
  59. default :
  60. return offset;
  61. }
  62. offset += ipv6_optlen(exthdr);
  63. *nexthdr = &exthdr->nexthdr;
  64. exthdr = (struct ipv6_opt_hdr *)(skb_network_header(skb) +
  65. offset);
  66. }
  67. return offset;
  68. }
  69. EXPORT_SYMBOL(ip6_find_1stfragopt);
  70. #if IS_ENABLED(CONFIG_IPV6)
  71. int ip6_dst_hoplimit(struct dst_entry *dst)
  72. {
  73. int hoplimit = dst_metric_raw(dst, RTAX_HOPLIMIT);
  74. if (hoplimit == 0) {
  75. struct net_device *dev = dst->dev;
  76. struct inet6_dev *idev;
  77. rcu_read_lock();
  78. idev = __in6_dev_get(dev);
  79. if (idev)
  80. hoplimit = idev->cnf.hop_limit;
  81. else
  82. hoplimit = dev_net(dev)->ipv6.devconf_all->hop_limit;
  83. rcu_read_unlock();
  84. }
  85. return hoplimit;
  86. }
  87. EXPORT_SYMBOL(ip6_dst_hoplimit);
  88. #endif
  89. int __ip6_local_out(struct sk_buff *skb)
  90. {
  91. int len;
  92. len = skb->len - sizeof(struct ipv6hdr);
  93. if (len > IPV6_MAXPLEN)
  94. len = 0;
  95. ipv6_hdr(skb)->payload_len = htons(len);
  96. return nf_hook(NFPROTO_IPV6, NF_INET_LOCAL_OUT, skb, NULL,
  97. skb_dst(skb)->dev, dst_output);
  98. }
  99. EXPORT_SYMBOL_GPL(__ip6_local_out);
  100. int ip6_local_out(struct sk_buff *skb)
  101. {
  102. int err;
  103. err = __ip6_local_out(skb);
  104. if (likely(err == 1))
  105. err = dst_output(skb);
  106. return err;
  107. }
  108. EXPORT_SYMBOL_GPL(ip6_local_out);