/* SPDX-License-Identifier: (BSD-2-Clause OR GPL-2.0-or-later)
 *
 * vim:set noexpandtab shiftwidth=8 softtabstop=8 fileencoding=utf-8:
 *
 * Compatibility functions and defines
 */

#ifndef NETWORK_KMODS_COMPAT_H
#define NETWORK_KMODS_COMPAT_H

#include <linux/version.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/if_vlan.h>

#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
#define skb_vlan_tag_get_id    vlan_tx_tag_get_id
#define skb_vlan_tag_get       vlan_tx_tag_get
#define skb_vlan_tag_present   vlan_tx_tag_present
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)
static inline bool skb_vlan_tagged(const struct sk_buff *skb)
{
	if (!skb_vlan_tag_present(skb) &&
	    likely(skb->protocol != htons(ETH_P_8021Q) &&
		   skb->protocol != htons(ETH_P_8021AD)))
		return false;

	return true;

}

#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0)
#define NETIF_F_GSO_ENCAP_ALL  (NETIF_F_GSO_GRE|NETIF_F_GSO_UDP_TUNNEL)
#endif

#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
#define NETIF_F_SCTP_CRC NETIF_F_SCTP_CSUM
#endif

#endif /* NETWORK_KMODS_COMPAT_H */