--- zzzz-none-000/linux-4.4.271/include/linux/skbuff.h 2021-06-03 06:22:09.000000000 +0000 +++ hawkeye-5590-750/linux-4.4.271/include/linux/skbuff.h 2023-04-19 10:22:30.000000000 +0000 @@ -39,6 +39,17 @@ #include #include +#include + +/* Do not include avm_pa.h to avoid include cycle. Since we can't determine + * the size here we reserve some space, including some extra space for future + * extensions without having to rebuild the world. + * + * avm_pa contains a BUILD_BUG_ON() in case the reserve is too small. + */ +#define AVM_PA_PKT_INFO_SKB_RESERVE 256 +struct avm_pa_pkt_info; + /* A. Checksumming of received packets by device. * * CHECKSUM_NONE: @@ -402,6 +413,8 @@ SKB_GSO_UDP_TUNNEL_CSUM = 1 << 11, SKB_GSO_TUNNEL_REMCSUM = 1 << 12, + + SKB_GSO_UDP_L4 = 1 << 17, }; #if BITS_PER_LONG > 32 @@ -565,6 +578,9 @@ }; struct net_device *dev; +#if IS_ENABLED(CONFIG_AVM_NET_SKB_INPUT_DEV) + struct net_device *input_dev; +#endif /* * This is the control buffer. It is free to use for every @@ -579,9 +595,21 @@ #ifdef CONFIG_XFRM struct sec_path *sp; #endif +#ifdef CONFIG_AVM_ENHANCED + /* uniq_id: Attention! This field does not exist in the 2.6.32 kernel + * anymore. We just use it to pass port and queue information between + * avm_cpmac and multid/dsld in the upper eight bits. */ + unsigned long uniq_id; +#define AVM_HAVE_SKB_UNIQ_ID +#endif #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) struct nf_conntrack *nfct; #endif +#if IS_ENABLED(CONFIG_AVM_PA_GENERIC_CT) + struct generic_ct_data ct_data; +#define SKB_GENERIC_CT(skb) ((skb)->ct_data.generic_ct) +#define SKB_GENERIC_CT_DIR(skb) ((skb)->ct_data.generic_ct_dir) +#endif #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) struct nf_bridge_info *nf_bridge; #endif @@ -647,7 +675,12 @@ __u8 inner_protocol_type:1; __u8 remcsum_offload:1; - /* 3 or 5 bit hole */ + __u8 gro_skip:1; + __u8 fast_forwarded:1; +#ifdef CONFIG_AVM_WAR_SKB_HAS_VLAN_DEI + __u8 vlan_dei:1; +#endif + /* 0, 1, 2 or 3 bit hole */ #ifdef CONFIG_NET_SCHED __u16 tc_index; /* traffic control index */ @@ -704,6 +737,13 @@ /* private: */ __u32 headers_end[0]; + +#ifdef CONFIG_AVM_PA + __u8 avm_pa[AVM_PA_PKT_INFO_SKB_RESERVE]; +#define AVM_PKT_INFO(skb) ((struct avm_pa_pkt_info *) (skb)->avm_pa) +#else +#define AVM_PKT_INFO(skb) ((struct avm_pa_pkt_info *) NULL) +#endif /* public: */ /* These elements must be at the end, see alloc_skb() for details. */ @@ -713,6 +753,12 @@ *data; unsigned int truesize; atomic_t users; +#ifdef CONFIG_DEBUG_OBJECTS_SKBUFF +#define DEBUG_OBJECTS_SKBUFF_STACKSIZE 20 + void *free_addr[DEBUG_OBJECTS_SKBUFF_STACKSIZE]; + void *alloc_addr[DEBUG_OBJECTS_SKBUFF_STACKSIZE]; + u32 sum; +#endif }; #ifdef __KERNEL__ @@ -805,6 +851,8 @@ void consume_skb(struct sk_buff *skb); void __kfree_skb(struct sk_buff *skb); extern struct kmem_cache *skbuff_head_cache; +extern void kfree_skbmem(struct sk_buff *skb); +extern void skb_release_data(struct sk_buff *skb); void kfree_skb_partial(struct sk_buff *skb, bool head_stolen); bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from, @@ -1827,6 +1875,52 @@ return tmp; } +static inline void *__skb_put_zero(struct sk_buff *skb, unsigned int len) +{ + void *tmp = __skb_put(skb, len); + + memset(tmp, 0, len); + return tmp; +} + +static inline void *__skb_put_data(struct sk_buff *skb, const void *data, + unsigned int len) +{ + void *tmp = __skb_put(skb, len); + + memcpy(tmp, data, len); + return tmp; +} + +static inline void __skb_put_u8(struct sk_buff *skb, u8 val) +{ + *(u8 *)__skb_put(skb, 1) = val; +} + +static inline void *skb_put_zero(struct sk_buff *skb, unsigned int len) +{ + void *tmp = skb_put(skb, len); + + memset(tmp, 0, len); + + return tmp; +} + +static inline void *skb_put_data(struct sk_buff *skb, const void *data, + unsigned int len) +{ + void *tmp = skb_put(skb, len); + + memcpy(tmp, data, len); + + return tmp; +} + +static inline void skb_put_u8(struct sk_buff *skb, u8 val) +{ + *(u8 *)skb_put(skb, 1) = val; +} + unsigned char *skb_push(struct sk_buff *skb, unsigned int len); static inline unsigned char *__skb_push(struct sk_buff *skb, unsigned int len) { @@ -2195,7 +2289,7 @@ * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8) */ #ifndef NET_SKB_PAD -#define NET_SKB_PAD max(32, L1_CACHE_BYTES) +#define NET_SKB_PAD max(64, L1_CACHE_BYTES) #endif int ___pskb_trim(struct sk_buff *skb, unsigned int len); @@ -2225,6 +2319,10 @@ return (len < skb->len) ? __pskb_trim(skb, len) : 0; } +extern struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev, + unsigned int length, gfp_t gfp); + + /** * pskb_trim_unique - remove end from a paged unique (not cloned) buffer * @skb: buffer to alter @@ -2240,6 +2338,24 @@ BUG_ON(err); } +/* + * Caller wants to reduce memory needs before queueing skb + * The (expensive) copy should not be be done in fast path. + */ +static inline struct sk_buff *skb_reduce_truesize(struct sk_buff *skb) +{ + if (skb->truesize > 2 * SKB_TRUESIZE(skb->len)) { + struct sk_buff *nskb; + nskb = skb_copy_expand(skb, skb_headroom(skb), 0, + GFP_ATOMIC | __GFP_NOWARN); + if (nskb) { + __kfree_skb(skb); + skb = nskb; + } + } + return skb; +} + /** * skb_orphan - orphan a buffer * @skb: buffer to orphan @@ -2331,16 +2447,6 @@ } -static inline struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev, - unsigned int length, gfp_t gfp) -{ - struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp); - - if (NET_IP_ALIGN && skb) - skb_reserve(skb, NET_IP_ALIGN); - return skb; -} - static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev, unsigned int length) { @@ -3382,6 +3488,28 @@ skb->csum = csum_add(skb->csum, delta); } +#if IS_ENABLED(CONFIG_AVM_PA_GENERIC_CT) +static inline void generic_ct_reset(struct sk_buff *skb) +{ + generic_ct_put(SKB_GENERIC_CT(skb)); + SKB_GENERIC_CT(skb) = NULL; +} + +static inline void __generic_ct_copy(struct sk_buff *dst, + const struct sk_buff *src) +{ + SKB_GENERIC_CT(dst) = generic_ct_get(SKB_GENERIC_CT(src)); + SKB_GENERIC_CT_DIR(dst) = SKB_GENERIC_CT_DIR(src); +} + +static inline void generic_ct_copy(struct sk_buff *dst, + const struct sk_buff *src) +{ + generic_ct_put(SKB_GENERIC_CT(dst)); + __generic_ct_copy(dst, src); +} +#endif + #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) void nf_conntrack_destroy(struct nf_conntrack *nfct); static inline void nf_conntrack_put(struct nf_conntrack *nfct) @@ -3395,6 +3523,7 @@ atomic_inc(&nfct->use); } #endif + #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge) { @@ -3407,7 +3536,8 @@ atomic_inc(&nf_bridge->use); } #endif /* CONFIG_BRIDGE_NETFILTER */ -static inline void nf_reset(struct sk_buff *skb) + +static inline void nf_reset_no_generic_ct(struct sk_buff *skb) { #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) nf_conntrack_put(skb->nfct); @@ -3419,6 +3549,14 @@ #endif } +static inline void nf_reset(struct sk_buff *skb) +{ + nf_reset_no_generic_ct(skb); +#if IS_ENABLED(CONFIG_AVM_PA_GENERIC_CT) + generic_ct_reset(skb); +#endif +} + static inline void nf_reset_trace(struct sk_buff *skb) { #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE) || defined(CONFIG_NF_TABLES) @@ -3434,8 +3572,9 @@ } /* Note: This doesn't put any conntrack and bridge info in dst. */ -static inline void __nf_copy(struct sk_buff *dst, const struct sk_buff *src, - bool copy) +static inline void __nf_copy_no_generic_ct(struct sk_buff *dst, + const struct sk_buff *src, + bool copy) { #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) dst->nfct = src->nfct; @@ -3453,7 +3592,17 @@ #endif } -static inline void nf_copy(struct sk_buff *dst, const struct sk_buff *src) +/* Note: This doesn't put any conntrack and bridge info in dst. */ +static inline void __nf_copy(struct sk_buff *dst, const struct sk_buff *src, + bool copy) +{ + __nf_copy_no_generic_ct(dst, src, copy); +#if IS_ENABLED(CONFIG_AVM_PA_GENERIC_CT) + __generic_ct_copy(dst, src); +#endif +} + +static inline void nf_copy_no_generic_ct(struct sk_buff *dst, const struct sk_buff *src) { #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) nf_conntrack_put(dst->nfct); @@ -3461,7 +3610,15 @@ #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) nf_bridge_put(dst->nf_bridge); #endif - __nf_copy(dst, src, true); + __nf_copy_no_generic_ct(dst, src, true); +} + +static inline void nf_copy(struct sk_buff *dst, const struct sk_buff *src) +{ + nf_copy_no_generic_ct(dst, src); +#if IS_ENABLED(CONFIG_AVM_PA_GENERIC_CT) + generic_ct_copy(dst, src); +#endif } #ifdef CONFIG_NETWORK_SECMARK