tun_proto.h 988 B

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