Taylor R Campbell
2016-01-16 23:57:13 UTC
The ip_output function must be called as
ip_output(m, opt, ro, flags, mopt, so)
where the arguments have the types
struct mbuf *m;
struct mbuf *opt;
struct route *ro;
int flags;
struct ip_moptions *mopt;
struct socket *so;
However, the prototype for ip_output is variadic:
int ip_output(struct mbuf *, ...);
This is silly. The only reason it is like this is that it is put in
the pr_output member of a struct protosw somewhere -- and then never
used via that path. There's no way you could use it if you didn't
know the protocol you were using, so this pr_output member can't be
used anyway unless you know a priori that you're in netinet. The same
is true of every other pr_output routine.
The only pr_output members that are ever actually used are (net/route)
rtsock's and (netipsec) keysock's, via raw_send.
The attached patch eliminates the pr_output member of struct protosw
(and struct ip6protosw), and adds an explicit (fully typed) callback
to raw_send for use by rtsock and keysock.
A subsequent patch may give ip_output &c. fully typed prototypes and
avoid varargs altogether, but I'll defer that for now. I would like
to apply similar treatment to pr_input, but again in another (somewhat
more involved) patch.
Thoughts? Objections?
ip_output(m, opt, ro, flags, mopt, so)
where the arguments have the types
struct mbuf *m;
struct mbuf *opt;
struct route *ro;
int flags;
struct ip_moptions *mopt;
struct socket *so;
However, the prototype for ip_output is variadic:
int ip_output(struct mbuf *, ...);
This is silly. The only reason it is like this is that it is put in
the pr_output member of a struct protosw somewhere -- and then never
used via that path. There's no way you could use it if you didn't
know the protocol you were using, so this pr_output member can't be
used anyway unless you know a priori that you're in netinet. The same
is true of every other pr_output routine.
The only pr_output members that are ever actually used are (net/route)
rtsock's and (netipsec) keysock's, via raw_send.
The attached patch eliminates the pr_output member of struct protosw
(and struct ip6protosw), and adds an explicit (fully typed) callback
to raw_send for use by rtsock and keysock.
A subsequent patch may give ip_output &c. fully typed prototypes and
avoid varargs altogether, but I'll defer that for now. I would like
to apply similar treatment to pr_input, but again in another (somewhat
more involved) patch.
Thoughts? Objections?