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