tun_proto.h 1015 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef __NET_TUN_PROTO_H
  2. #define __NET_TUN_PROTO_H
  3. #include <linux/if_ether.h>
  4. #include <linux/types.h>
  5. /* One byte protocol values as defined by VXLAN-GPE and NSH. These will
  6. * hopefully get a shared IANA registry.
  7. */
  8. #define TUN_P_IPV4 0x01
  9. #define TUN_P_IPV6 0x02
  10. #define TUN_P_ETHERNET 0x03
  11. #define TUN_P_NSH 0x04
  12. #define TUN_P_MPLS_UC 0x05
  13. static inline __be16 tun_p_to_eth_p(u8 proto)
  14. {
  15. switch (proto) {
  16. case TUN_P_IPV4:
  17. return htons(ETH_P_IP);
  18. case TUN_P_IPV6:
  19. return htons(ETH_P_IPV6);
  20. case TUN_P_ETHERNET:
  21. return htons(ETH_P_TEB);
  22. case TUN_P_NSH:
  23. return htons(ETH_P_NSH);
  24. case TUN_P_MPLS_UC:
  25. return htons(ETH_P_MPLS_UC);
  26. }
  27. return 0;
  28. }
  29. static inline u8 tun_p_from_eth_p(__be16 proto)
  30. {
  31. switch (proto) {
  32. case htons(ETH_P_IP):
  33. return TUN_P_IPV4;
  34. case htons(ETH_P_IPV6):
  35. return TUN_P_IPV6;
  36. case htons(ETH_P_TEB):
  37. return TUN_P_ETHERNET;
  38. case htons(ETH_P_NSH):
  39. return TUN_P_NSH;
  40. case htons(ETH_P_MPLS_UC):
  41. return TUN_P_MPLS_UC;
  42. }
  43. return 0;
  44. }
  45. #endif