Date: Fri, 27 Mar 2015 13:26:59 +0000 (UTC) From: Fabien Thomas <fabient@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r280759 - head/sys/netinet Message-ID: <201503271326.t2RDQxd3056112@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: fabient Date: Fri Mar 27 13:26:59 2015 New Revision: 280759 URL: https://svnweb.freebsd.org/changeset/base/280759 Log: On multi CPU systems, we may emit successive packets with the same id. Fix the race by using an atomic operation. Differential Revision: https://reviews.freebsd.org/D2141 Obtained from: emeric.poupon@stormshield.eu MFC after: 1 week Sponsored by: Stormshield Modified: head/sys/netinet/ip_output.c head/sys/netinet/ip_var.h Modified: head/sys/netinet/ip_output.c ============================================================================== --- head/sys/netinet/ip_output.c Fri Mar 27 12:45:20 2015 (r280758) +++ head/sys/netinet/ip_output.c Fri Mar 27 13:26:59 2015 (r280759) @@ -91,7 +91,7 @@ __FBSDID("$FreeBSD$"); #include <security/mac/mac_framework.h> -VNET_DEFINE(u_short, ip_id); +VNET_DEFINE(uint32_t, ip_id); #ifdef MBUF_STRESS_TEST static int mbuf_frag_size = 0; Modified: head/sys/netinet/ip_var.h ============================================================================== --- head/sys/netinet/ip_var.h Fri Mar 27 12:45:20 2015 (r280758) +++ head/sys/netinet/ip_var.h Fri Mar 27 13:26:59 2015 (r280759) @@ -174,7 +174,7 @@ struct inpcb; struct route; struct sockopt; -VNET_DECLARE(u_short, ip_id); /* ip packet ctr, for ids */ +VNET_DECLARE(uint32_t, ip_id); /* ip packet ctr, for ids */ VNET_DECLARE(int, ip_defttl); /* default IP ttl */ VNET_DECLARE(int, ipforwarding); /* ip forwarding */ #ifdef IPSTEALTH @@ -228,7 +228,7 @@ struct in_ifaddr * void ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *, struct mbuf *); void ip_slowtimo(void); -u_int16_t ip_randomid(void); +uint16_t ip_randomid(void); int rip_ctloutput(struct socket *, struct sockopt *); void rip_ctlinput(int, struct sockaddr *, void *); void rip_init(void); @@ -305,8 +305,18 @@ extern int (*ip_dn_io_ptr)(struct mbuf * VNET_DECLARE(int, ip_do_randomid); #define V_ip_do_randomid VNET(ip_do_randomid) -#define ip_newid() ((V_ip_do_randomid != 0) ? ip_randomid() : \ - htons(V_ip_id++)) +static __inline uint16_t +ip_newid(void) +{ + uint16_t res; + + if (V_ip_do_randomid != 0) + return (ip_randomid()); + else { + res = atomic_fetchadd_32(&V_ip_id, 1) & 0xFFFF; + return (htons(res)); + } +} #endif /* _KERNEL */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201503271326.t2RDQxd3056112>