Subject: Re: [PATCH ipsec-next v12 08/16] xfrm: iptfs: add user packet (tunnel ingress) handling

From: Christian Hopps <[email-masked]>
Date: Sat, 02 Nov 2024 15:44:25 +0000

Steffen Klassert <[email-masked]> writes:

> On Mon, Oct 07, 2024 at 09:59:20AM -0400, Christian Hopps wrote:
>> From: Christian Hopps <[email-masked]>
>> @@ -77,8 +609,11 @@ static int iptfs_user_init(struct net *net, struct xfrm_state *x,
>>  {
>>  	struct xfrm_iptfs_data *xtfs = x->mode_data;
>>  	struct xfrm_iptfs_config *xc;
>> +	u64 q;
>>
>>  	xc = &xtfs->cfg;
>> +	xc->max_queue_size = IPTFS_DEFAULT_MAX_QUEUE_SIZE;
>> +	xtfs->init_delay_ns = IPTFS_DEFAULT_INIT_DELAY_USECS * NSECS_IN_USEC;
>>
>>  	if (attrs[XFRMA_IPTFS_PKT_SIZE]) {
>>  		xc->pkt_size = nla_get_u32(attrs[XFRMA_IPTFS_PKT_SIZE]);
>> @@ -92,6 +627,17 @@ static int iptfs_user_init(struct net *net, struct xfrm_state *x,
>>  			return -EINVAL;
>>  		}
>>  	}
>> +	if (attrs[XFRMA_IPTFS_MAX_QSIZE])
>> +		xc->max_queue_size = nla_get_u32(attrs[XFRMA_IPTFS_MAX_QSIZE]);
>> +	if (attrs[XFRMA_IPTFS_INIT_DELAY])
>> +		xtfs->init_delay_ns =
>> +			(u64)nla_get_u32(attrs[XFRMA_IPTFS_INIT_DELAY]) *
>> +			NSECS_IN_USEC;
>> +
>> +	q = (u64)xc->max_queue_size * 95;
>> +	(void)do_div(q, 100);
>
> This cast is not need.

Removed.

FWIW, the cast was to document the ignoring of the returned remainder value; however, this is outside the normal linux kernel coding style.

>> +	xtfs->ecn_queue_size = (u32)q;
>> +
>>  	return 0;
>>  }
>>
>> @@ -101,8 +647,11 @@ static unsigned int iptfs_sa_len(const struct xfrm_state *x)
>>  	struct xfrm_iptfs_config *xc = &xtfs->cfg;
>>  	unsigned int l = 0;
>>
>> -	if (x->dir == XFRM_SA_DIR_OUT)
>> +	if (x->dir == XFRM_SA_DIR_OUT) {
>> +		l += nla_total_size(sizeof(u32)); /* init delay usec */
>> +		l += nla_total_size(sizeof(xc->max_queue_size));
>>  		l += nla_total_size(sizeof(xc->pkt_size));
>> +	}
>>
>>  	return l;
>>  }
>> @@ -112,9 +661,22 @@ static int iptfs_copy_to_user(struct xfrm_state *x, struct sk_buff *skb)
>>  	struct xfrm_iptfs_data *xtfs = x->mode_data;
>>  	struct xfrm_iptfs_config *xc = &xtfs->cfg;
>>  	int ret = 0;
>> +	u64 q;
>> +
>> +	if (x->dir == XFRM_SA_DIR_OUT) {
>> +		q = xtfs->init_delay_ns;
>> +		(void)do_div(q, NSECS_IN_USEC);
>
> Same here.

Removed.