output_core.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
  11. {
  12. u16 offset = sizeof(struct ipv6hdr);
  13. struct ipv6_opt_hdr *exthdr =
  14. (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1);
  15. unsigned int packet_len = skb_tail_pointer(skb) -
  16. skb_network_header(skb);
  17. int found_rhdr = 0;
  18. *nexthdr = &ipv6_hdr(skb)->nexthdr;
  19. while (offset + 1 <= packet_len) {
  20. switch (**nexthdr) {
  21. case NEXTHDR_HOP:
  22. break;
  23. case NEXTHDR_ROUTING:
  24. found_rhdr = 1;
  25. break;
  26. case NEXTHDR_DEST:
  27. #if IS_ENABLED(CONFIG_IPV6_MIP6)
  28. if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0)
  29. break;
  30. #endif
  31. if (found_rhdr)
  32. return offset;
  33. break;
  34. default :
  35. return offset;
  36. }
  37. offset += ipv6_optlen(exthdr);
  38. *nexthdr = &exthdr->nexthdr;
  39. exthdr = (struct ipv6_opt_hdr *)(skb_network_header(skb) +
  40. offset);
  41. }
  42. return offset;
  43. }
  44. EXPORT_SYMBOL(ip6_find_1stfragopt);
  45. #if IS_ENABLED(CONFIG_IPV6)
  46. int ip6_dst_hoplimit(struct dst_entry *dst)
  47. {
  48. int hoplimit = dst_metric_raw(dst, RTAX_HOPLIMIT);
  49. if (hoplimit == 0) {
  50. struct net_device *dev = dst->dev;
  51. struct inet6_dev *idev;
  52. rcu_read_lock();
  53. idev = __in6_dev_get(dev);
  54. if (idev)
  55. hoplimit = idev->cnf.hop_limit;
  56. else
  57. hoplimit = dev_net(dev)->ipv6.devconf_all->hop_limit;
  58. rcu_read_unlock();
  59. }
  60. return hoplimit;
  61. }
  62. EXPORT_SYMBOL(ip6_dst_hoplimit);
  63. #endif
  64. int __ip6_local_out(struct sk_buff *skb)
  65. {
  66. int len;
  67. len = skb->len - sizeof(struct ipv6hdr);
  68. if (len > IPV6_MAXPLEN)
  69. len = 0;
  70. ipv6_hdr(skb)->payload_len = htons(len);
  71. IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr);
  72. return nf_hook(NFPROTO_IPV6, NF_INET_LOCAL_OUT, skb, NULL,
  73. skb_dst(skb)->dev, dst_output);
  74. }
  75. EXPORT_SYMBOL_GPL(__ip6_local_out);
  76. int ip6_local_out(struct sk_buff *skb)
  77. {
  78. int err;
  79. err = __ip6_local_out(skb);
  80. if (likely(err == 1))
  81. err = dst_output(skb);
  82. return err;
  83. }
  84. EXPORT_SYMBOL_GPL(ip6_local_out);