18c2ecf20Sopenharmony_ci#ifndef __NET_TUN_PROTO_H
28c2ecf20Sopenharmony_ci#define __NET_TUN_PROTO_H
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include <linux/kernel.h>
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci/* One byte protocol values as defined by VXLAN-GPE and NSH. These will
78c2ecf20Sopenharmony_ci * hopefully get a shared IANA registry.
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#define TUN_P_IPV4      0x01
108c2ecf20Sopenharmony_ci#define TUN_P_IPV6      0x02
118c2ecf20Sopenharmony_ci#define TUN_P_ETHERNET  0x03
128c2ecf20Sopenharmony_ci#define TUN_P_NSH       0x04
138c2ecf20Sopenharmony_ci#define TUN_P_MPLS_UC   0x05
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistatic inline __be16 tun_p_to_eth_p(u8 proto)
168c2ecf20Sopenharmony_ci{
178c2ecf20Sopenharmony_ci	switch (proto) {
188c2ecf20Sopenharmony_ci	case TUN_P_IPV4:
198c2ecf20Sopenharmony_ci		return htons(ETH_P_IP);
208c2ecf20Sopenharmony_ci	case TUN_P_IPV6:
218c2ecf20Sopenharmony_ci		return htons(ETH_P_IPV6);
228c2ecf20Sopenharmony_ci	case TUN_P_ETHERNET:
238c2ecf20Sopenharmony_ci		return htons(ETH_P_TEB);
248c2ecf20Sopenharmony_ci	case TUN_P_NSH:
258c2ecf20Sopenharmony_ci		return htons(ETH_P_NSH);
268c2ecf20Sopenharmony_ci	case TUN_P_MPLS_UC:
278c2ecf20Sopenharmony_ci		return htons(ETH_P_MPLS_UC);
288c2ecf20Sopenharmony_ci	}
298c2ecf20Sopenharmony_ci	return 0;
308c2ecf20Sopenharmony_ci}
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistatic inline u8 tun_p_from_eth_p(__be16 proto)
338c2ecf20Sopenharmony_ci{
348c2ecf20Sopenharmony_ci	switch (proto) {
358c2ecf20Sopenharmony_ci	case htons(ETH_P_IP):
368c2ecf20Sopenharmony_ci		return TUN_P_IPV4;
378c2ecf20Sopenharmony_ci	case htons(ETH_P_IPV6):
388c2ecf20Sopenharmony_ci		return TUN_P_IPV6;
398c2ecf20Sopenharmony_ci	case htons(ETH_P_TEB):
408c2ecf20Sopenharmony_ci		return TUN_P_ETHERNET;
418c2ecf20Sopenharmony_ci	case htons(ETH_P_NSH):
428c2ecf20Sopenharmony_ci		return TUN_P_NSH;
438c2ecf20Sopenharmony_ci	case htons(ETH_P_MPLS_UC):
448c2ecf20Sopenharmony_ci		return TUN_P_MPLS_UC;
458c2ecf20Sopenharmony_ci	}
468c2ecf20Sopenharmony_ci	return 0;
478c2ecf20Sopenharmony_ci}
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#endif
50