Re: [PATCH net-next v3 1/4] netfilter: conntrack: add shared port and uint parsers for helpers

Pablo Neira Ayuso
2026-05-05T22:33:22Z

On Sun, May 03, 2026 at 02:02:17PM +0530, HACKE-RC wrote:
> Add nf_ct_helper_parse_uint() for bounded unsigned integer parsing
> from an unterminated buffer, and nf_ct_helper_parse_port() which calls
> it with max=65535 and rejects port zero. Both helpers are exported so
> conntrack protocol helpers can replace ad-hoc simple_strtoul() usage.
>
> Signed-off-by: HACKE-RC <rc@rexion.ai>

You will need a "real name" here.

> ---
> include/net/netfilter/nf_conntrack_helper.h | 5 +++
> net/netfilter/nf_conntrack_helper.c | 39 +++++++++++++++++++++
> 2 files changed, 44 insertions(+)
>
> diff --git a/include/net/netfilter/nf_conntrack_helper.h b/include/net/netfilter/nf_conntrack_helper.h
> index de2f956ab..ab145fcd9 100644
> --- a/include/net/netfilter/nf_conntrack_helper.h
> +++ b/include/net/netfilter/nf_conntrack_helper.h
> @@ -160,6 +160,11 @@ nf_ct_helper_expectfn_find_by_name(const char *name);
> struct nf_ct_helper_expectfn *
> nf_ct_helper_expectfn_find_by_symbol(const void *symbol);
>
> +int nf_ct_helper_parse_uint(const char *cp, unsigned int len,
> + unsigned long max, unsigned long *val, char **endp);
> +int nf_ct_helper_parse_port(const char *cp, unsigned int len,
> + u16 *port, char **endp);
> +
> extern struct hlist_head *nf_ct_helper_hash;
> extern unsigned int nf_ct_helper_hsize;
>
> diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
> index a715304a5..f6229957c 100644
> --- a/net/netfilter/nf_conntrack_helper.c
> +++ b/net/netfilter/nf_conntrack_helper.c
> @@ -499,6 +499,45 @@ void nf_nat_helper_unregister(struct nf_conntrack_nat_helper *nat)
> }
> EXPORT_SYMBOL_GPL(nf_nat_helper_unregister);
>
> +int nf_ct_helper_parse_uint(const char *cp, unsigned int len,
> + unsigned long max, unsigned long *val, char **endp)

In nf.git, there is a new function sip_strtouint() that can possibly
be moved to nf_conntrack_helper.c.

Thanks.