output_core.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
  9. {
  10. static atomic_t ipv6_fragmentation_id;
  11. int old, new;
  12. #if IS_ENABLED(CONFIG_IPV6)
  13. if (rt && !(rt->dst.flags & DST_NOPEER)) {
  14. struct inet_peer *peer;
  15. struct net *net;
  16. net = dev_net(rt->dst.dev);
  17. peer = inet_getpeer_v6(net->ipv6.peers, &rt->rt6i_dst.addr, 1);
  18. if (peer) {
  19. fhdr->identification = htonl(inet_getid(peer, 0));
  20. inet_putpeer(peer);
  21. return;
  22. }
  23. }
  24. #endif
  25. do {
  26. old = atomic_read(&ipv6_fragmentation_id);
  27. new = old + 1;
  28. if (!new)
  29. new = 1;
  30. } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
  31. fhdr->identification = htonl(new);
  32. }
  33. EXPORT_SYMBOL(ipv6_select_ident);
  34. int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
  35. {
  36. u16 offset = sizeof(struct ipv6hdr);
  37. struct ipv6_opt_hdr *exthdr =
  38. (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1);
  39. unsigned int packet_len = skb_tail_pointer(skb) -
  40. skb_network_header(skb);
  41. int found_rhdr = 0;
  42. *nexthdr = &ipv6_hdr(skb)->nexthdr;
  43. while (offset + 1 <= packet_len) {
  44. switch (**nexthdr) {
  45. case NEXTHDR_HOP:
  46. break;
  47. case NEXTHDR_ROUTING:
  48. found_rhdr = 1;
  49. break;
  50. case NEXTHDR_DEST:
  51. #if IS_ENABLED(CONFIG_IPV6_MIP6)
  52. if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0)
  53. break;
  54. #endif
  55. if (found_rhdr)
  56. return offset;
  57. break;
  58. default :
  59. return offset;
  60. }
  61. offset += ipv6_optlen(exthdr);
  62. *nexthdr = &exthdr->nexthdr;
  63. exthdr = (struct ipv6_opt_hdr *)(skb_network_header(skb) +
  64. offset);
  65. }
  66. return offset;
  67. }
  68. EXPORT_SYMBOL(ip6_find_1stfragopt);