Commit abe6bde1 authored by chengjunjia's avatar chengjunjia
Browse files

net: tcp: Modify codes for better compatibility of code format

huawei inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IAZBRK


CVE: NA

--------------------------------------------------

1. Keep original process of kernel code
2. Change ip_output process to avoid #else
3. TCP mss should leave room for caqm
4. Not use the unuse in tcp_skb_cb
5. Change the CAQM TPID to a config value

Signed-off-by: default avatarchengjunjia <jiachengjun2@huawei.com>
parent 946747d4
Loading
Loading
Loading
Loading
+30 −22
Original line number Diff line number Diff line
@@ -27,16 +27,6 @@
#define CAQM_RECV_EN	(true)
#define CAQM_SEND_EN	(true)

/*
 * caqm_flags in tcp_sock alias ecn_flags(already used 1,2,4,8)
 */
#define TCP_CAQM_SRV (16)
#define TCP_CAQM_CLI (32)
#define TCP_CAQM_OK	(TCP_CAQM_SRV|TCP_CAQM_CLI)

#define TCP_EXFLAGS_CLI_CAQM (1)
#define TCP_EXFLAGS_SRV_CAQM (2)

#define FIXED_POINT_8 (8U)
#define FIXED_POINT_20 (20U)
#define FIXED_POINT_8_UNIT (1<<8U)
@@ -47,7 +37,6 @@ extern int sysctl_caqm_debug_info;
extern int sysctl_caqm_alpha_fx_8;
extern int sysctl_caqm_beta;
extern unsigned int sysctl_caqm_min_cwnd;
extern int sysctl_caqm_tpid;
extern int sysctl_caqm_mtu_unit;
extern int sysctl_caqm_data_hint_unit;
extern unsigned int sysctl_caqm_ack_hint_unit;
@@ -127,7 +116,7 @@ struct caqm_hdr {
 */
static inline bool eth_type_caqm(__be16 ethertype)
{
	return ethertype == htons(sysctl_caqm_tpid);
	return ethertype == htons(CONFIG_ETH_P_CAQM);
}

#define CAQM_PKT_ACK (0)
@@ -315,13 +304,13 @@ static inline __be16 caqm_get_protocol_and_depth_after_vlan(struct sk_buff *skb,
}
#endif

static inline struct sk_buff *skb_try_caqm_untag(struct sk_buff *skb)
static inline struct sk_buff *skb_caqm_untag(struct sk_buff *skb)
{
#ifdef CONFIG_ETH_CAQM
	struct caqm_hdr *chdr;
	u16 caqm_hdr_info;

	if (!static_branch_unlikely(&sysctl_caqm_enable) || !eth_type_caqm(skb->protocol))
	if (!static_branch_unlikely(&sysctl_caqm_enable))
		return skb;

	skb = skb_share_check(skb, GFP_ATOMIC);
@@ -430,7 +419,6 @@ static inline void skb_gro_caqm_untag(struct sk_buff *skb)
static inline __be16 caqm_get_protocol_and_depth(struct sk_buff *skb,
						 __be16 type, int *depth)
{
	type = vlan_get_protocol_and_depth(skb, type, depth);
	if (static_branch_unlikely(&sysctl_caqm_enable) && eth_type_caqm(type))
		return caqm_get_protocol_and_depth_after_vlan(skb, type, depth);
	else
@@ -451,27 +439,47 @@ static inline void caqm_update_hint_in_gro(struct sk_buff *skb, struct sk_buff *
#endif
}

static inline int caqm_add_eth_header(struct sk_buff *skb, unsigned short *type,
static inline void caqm_add_eth_header(struct sk_buff *skb, unsigned short *type,
			       struct net_device *dev)
{
#ifdef CONFIG_ETH_CAQM
	struct skb_caqm_info *cinfo = get_skb_caqm_info(skb);

	if (static_branch_unlikely(&sysctl_caqm_enable) &&
	    (sysctl_caqm_filter_nics & (1UL << dev->ifindex)) == 0)
	if (!static_branch_unlikely(&sysctl_caqm_enable))
		return;

	if ((sysctl_caqm_filter_nics & (1UL << dev->ifindex)) == 0)
		cinfo->send_en = 0;
	if (static_branch_unlikely(&sysctl_caqm_enable) && cinfo->send_en) {
	if (cinfo->send_en) {
		cinfo->send_en = 0;
		if (unlikely(skb_headroom(skb) <  ETH_HLEN + CAQM_HLEN))
			return -ETH_HLEN;
			return; // No enough room
		u16 *chdr = skb_push(skb, CAQM_HLEN);

		chdr[0] = (cinfo->send_hdr);
		chdr[1] = htons(*type);
		*type = (unsigned short)sysctl_caqm_tpid;
		*type = CONFIG_ETH_P_CAQM;
	}
#endif
	return 0;
}

static inline bool is_caqm_out_enable(struct sk_buff *skb,
				   struct net_device *dev)

{
#ifdef CONFIG_ETH_CAQM
	struct skb_caqm_info *cinfo = get_skb_caqm_info(skb);

	if (!static_branch_unlikely(&sysctl_caqm_enable))
		return false;

	// If the nic is not configed, the output packet has no caqm header
	if ((sysctl_caqm_filter_nics & (1UL << dev->ifindex)) == 0)
		cinfo->send_en = 0;
	if (cinfo->send_en)
		return true;
#endif
	return false;
}

#endif /* _LINUX_IF_CAQM_H_ */
+16 −1
Original line number Diff line number Diff line
@@ -523,7 +523,22 @@ config NETACC_TERRACE

config ETH_CAQM
	bool "Enable CAQM for Ethernet"
	default n
	help
	  Enable CAQM (Congestion-Aware Queue Management) for Ethernet layer.
	  Unsolved Problem: SYN/SYN-ACK process should be split from payload.
	  Before solving the problem above, the config should not be opened
	  for the openeuler_defconfig

config ETH_P_CAQM
	hex "CAQM TPID value"
	depends on ETH_CAQM
	default "0x8200"
	range 1501 0xFFFF
	help
	  Enable CAQM (Congestion-Aware Queue Management) for Ethernet drivers.
	  The CAQM TPID, i.e. the proto number for 802. Because the value is
	  not fixed now. We need to set it as a config parameter.
	  See IANA spec to avoid conflict:
	    https://www.iana.org/assignments/ieee-802-numbers

endif   # if NET
+11 −10
Original line number Diff line number Diff line
@@ -3398,11 +3398,11 @@ __be16 skb_network_protocol(struct sk_buff *skb, int *depth)
		eth = (struct ethhdr *)skb->data;
		type = eth->h_proto;
	}
	type = vlan_get_protocol_and_depth(skb, type, depth);
#ifdef CONFIG_ETH_CAQM
	return caqm_get_protocol_and_depth(skb, type, depth);
#else
	return vlan_get_protocol_and_depth(skb, type, depth);
	type = caqm_get_protocol_and_depth(skb, type, depth);
#endif
	return type;
}


@@ -5327,16 +5327,15 @@ EXPORT_SYMBOL_GPL(netdev_rx_handler_unregister);
 */
static bool skb_pfmemalloc_protocol(struct sk_buff *skb)
{
#ifdef CONFIG_ETH_CAQM
	if (static_branch_unlikely(&sysctl_caqm_enable) && skb->protocol == htons(sysctl_caqm_tpid))
		return true;
#endif
	switch (skb->protocol) {
	case htons(ETH_P_ARP):
	case htons(ETH_P_IP):
	case htons(ETH_P_IPV6):
	case htons(ETH_P_8021Q):
	case htons(ETH_P_8021AD):
#ifdef CONFIG_ETH_CAQM
	case htons(CONFIG_ETH_P_CAQM):
#endif
		return true;
	default:
		return false;
@@ -5411,9 +5410,11 @@ static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc,
	}

#ifdef CONFIG_ETH_CAQM
	skb = skb_try_caqm_untag(skb);
	if (eth_type_caqm(skb->protocol)) {
		skb = skb_caqm_untag(skb);
		if (unlikely(!skb))
			goto out;
	}
#endif

	if (skb_skip_tc_classify(skb))
+6 −4
Original line number Diff line number Diff line
@@ -1475,12 +1475,14 @@ bool __skb_flow_dissect(const struct net *net,
					       nhoff, hlen);
		break;

	default:
	#ifdef CONFIG_ETH_CAQM
	case htons(CONFIG_ETH_P_CAQM):
		fdret = rps_try_skip_caqm_hdr(skb, data, &proto, &nhoff, hlen);
		#else
		fdret = FLOW_DISSECT_RET_OUT_BAD;
		break;
	#endif

	default:
		fdret = FLOW_DISSECT_RET_OUT_BAD;
		break;
	}

+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ static inline int rps_try_skip_caqm_hdr(const struct sk_buff *skb, const void *d
	const struct caqm_hdr *caqm = NULL;
	struct caqm_hdr _caqm;

	if (!static_branch_unlikely(&sysctl_caqm_enable) || !eth_type_caqm(*proto_ptr))
	if (!static_branch_unlikely(&sysctl_caqm_enable))
		return FLOW_DISSECT_RET_OUT_BAD;

	caqm = __skb_header_pointer(skb, *nhoff_ptr, sizeof(_caqm),
Loading