tech-net archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: patch make struct protosw pr_input non-variadic



   Date: Sat, 14 May 2016 15:29:36 -0400
   From: christos%zoulas.com@localhost (Christos Zoulas)

   But you are casting structs now... How is that safe?
   You might as well make it an array for void *'s...

Before, with casts for type puns and strict aliasing violation:

	struct protosw {
		int pr_type;
		int (*pr_input)(struct mbuf *, ...);
	};

	struct ip6protosw {
		int pr_type;
		int (*pr_input)(struct mbuf **, int *, int);
	};

	struct ip6protosw inet6sw[] = {
		{
			.pr_type = SOCK_DGRAM,
			.pr_input = udp6_input,
		},
		...
	};

	struct domain inet6domain = {
		/*
		 * Type pun in violation of strict aliasing.  inet6sw is *not*
		 * an array of struct protosw.
		 */
--->		.dom_protosw = (struct protosw *)inet6sw,
		...
	}

After, with neither casts nor void * nor strict aliasing violations:

	struct protosw {
		int pr_type;
	};

	struct ip6protosw {
		struct protosw ip6pr_protosw;
		int (*ip6pr_input)(struct mbuf **, int *, int);
	};

	struct ip6protosw inet6sw[] = {
		{
			.ip6pr_protosw = { .pr_type = SOCK_DGRAM },
			.ip6pr_input = udp6_input,
		},
		...
	};

	struct protosw *inet6protosw[] = {
		/* Effectively, this initializer, but written at run-time.  */
		&inet6sw[0].ip6pr_protosw,
		...
	};

	struct domain inet6domain = {
		/* No type pun: LHS and RHS are both struct protosw **.  */
--->		.dom_protosw = inet6protosw,
		...
	};

(But ip6_input still goes through inet6sw directly -- so there is no
change to the protocol-dispatching code in the packet-processing
path.)


Home | Main Index | Thread Index | Old Index