output_core.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 - skb->network_header;
  40. int found_rhdr = 0;
  41. *nexthdr = &ipv6_hdr(skb)->nexthdr;
  42. while (offset + 1 <= packet_len) {
  43. switch (**nexthdr) {
  44. case NEXTHDR_HOP:
  45. break;
  46. case NEXTHDR_ROUTING:
  47. found_rhdr = 1;
  48. break;
  49. case NEXTHDR_DEST:
  50. #if IS_ENABLED(CONFIG_IPV6_MIP6)
  51. if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0)
  52. break;
  53. #endif
  54. if (found_rhdr)
  55. return offset;
  56. break;
  57. default :
  58. return offset;
  59. }
  60. offset += ipv6_optlen(exthdr);
  61. *nexthdr = &exthdr->nexthdr;
  62. exthdr = (struct ipv6_opt_hdr *)(skb_network_header(skb) +
  63. offset);
  64. }
  65. return offset;
  66. }
  67. EXPORT_SYMBOL(ip6_find_1stfragopt);