Permalink
Browse files

revisit xx_ctlinput(). we cannot just invent function prototype for

xx_ctlinput() as they will be called across protocol types
(for example, see pfctlinput() in sys/kern).
make last arg of xx6_ctlinput() into void *, to meet standard practice.
for passing info from icmp6, introduced struct ip6ctlparam.

cleanup tcp6_ctlinput() for netbsd.

tested on: netbsd, freebsd2
commits for openbsd and freebsd3 should follow.
  • Loading branch information...
1 parent 9afe3af commit f0644f18163a5405922190eb38f831775e6a5df8 itojun committed Oct 10, 1999
@@ -735,13 +735,12 @@ icmp6_input(mp, offp, proto)
/* Detect the upper level protocol */
{
- void (*ctlfunc) __P((int, struct sockaddr *,
- struct ip6_hdr *,
- struct mbuf *, int)); /* XXX */
+ void (*ctlfunc) __P((int, struct sockaddr *, void *));
struct ip6_hdr *eip6 = (struct ip6_hdr *)(icmp6 + 1);
u_int8_t nxt = eip6->ip6_nxt;
int eoff = off + sizeof(struct icmp6_hdr) +
sizeof(struct ip6_hdr);
+ struct ip6ctlparam ip6cp;
while (1) { /* XXX: should avoid inf. loop explicitly? */
struct ip6_ext *eh;
@@ -774,14 +773,14 @@ icmp6_input(mp, offp, proto)
}
notify:
icmp6 = (struct icmp6_hdr *)(mtod(m, caddr_t) + off);
- ctlfunc = (void (*) __P((int, struct sockaddr *,
- struct ip6_hdr *,
- struct mbuf *, int)))
+ ctlfunc = (void (*) __P((int, struct sockaddr *, void *)))
(inet6sw[ip6_protox[nxt]].pr_ctlinput);
- if (ctlfunc)
- (*ctlfunc)(code, (struct sockaddr *)&icmp6src,
- (struct ip6_hdr *)(icmp6 + 1),
- m, eoff);
+ if (ctlfunc) {
+ ip6cp.ip6c_m = m;
+ ip6cp.ip6c_ip6 = (struct ip6_hdr *)(icmp6 + 1);
+ ip6cp.ip6c_off = eoff;
+ (*ctlfunc)(code, (struct sockaddr *)&icmp6src, &ip6cp);
+ }
}
break;
@@ -1592,7 +1591,7 @@ icmp6_redirect_input(m, off)
/* finally update cached route in each socket via pfctlinput */
{
struct sockaddr_in6 sdst;
-#if 0
+#if 1
#else
struct ip6protosw *pr;
#endif
@@ -1601,7 +1600,7 @@ icmp6_redirect_input(m, off)
sdst.sin6_family = AF_INET6;
sdst.sin6_len = sizeof(struct sockaddr_in6);
bcopy(&reddst6, &sdst.sin6_addr, sizeof(struct in6_addr));
-#if 0
+#if 1
pfctlinput(PRC_REDIRECT_HOST, (struct sockaddr *)&sdst);
#else
/*
@@ -83,6 +83,16 @@ struct ip6_hdr;
struct pr_usrreqs;
#endif
+/*
+ * argument type for the last arg of pr_ctlinput().
+ * should be consulted only with AF_INET6 family.
+ */
+struct ip6ctlparam {
+ struct mbuf *ip6c_m; /* start of mbuf chain */
+ struct ip6_hdr *ip6c_ip6; /* ip6 header of target packet */
+ int ip6c_off; /* offset of the target proto header */
+};
+
struct ip6protosw {
#if defined(__FreeBSD__) && __FreeBSD__ < 3
short pr_type; /* socket type used for */
@@ -103,8 +113,7 @@ struct ip6protosw {
__P((struct mbuf *, ...));
#endif
void (*pr_ctlinput) /* control input (from below) */
- __P((int, struct sockaddr *, struct ip6_hdr *,
- struct mbuf *, int));
+ __P((int, struct sockaddr *, void *));
int (*pr_ctloutput) /* control output (from above) */
__P((int, struct socket *, int, int, struct mbuf **));
@@ -112,6 +112,7 @@
#include <netinet6/tcp6_seq.h>
#include <netinet6/tcp6_timer.h>
#include <netinet6/tcp6_var.h>
+#include <netinet6/ip6protosw.h>
#ifdef IPSEC
#include <netinet6/ipsec.h>
@@ -541,18 +542,19 @@ tcp6_notify(in6p, error)
}
void
-tcp6_ctlinput(cmd, sa, ip6, m, off)
+tcp6_ctlinput(cmd, sa, d)
int cmd;
struct sockaddr *sa;
- register struct ip6_hdr *ip6;
- struct mbuf *m;
- int off;
+ void *d;
{
register struct tcp6hdr *thp;
struct tcp6hdr th;
void (*notify) __P((struct in6pcb *, int)) = tcp6_notify;
int nmatch;
struct sockaddr_in6 sa6;
+ struct mbuf *m;
+ struct ip6_hdr *ip6;
+ int off;
if (sa->sa_family != AF_INET6 ||
sa->sa_len != sizeof(struct sockaddr_in6))
@@ -565,6 +567,17 @@ tcp6_ctlinput(cmd, sa, ip6, m, off)
((unsigned)cmd > PRC_NCMDS || inet6ctlerrmap[cmd] == 0))
return;
+ /* if the parameter is from icmp6, decode it. */
+ if (d != NULL) {
+ struct ip6ctlparam *ip6cp = (struct ip6ctlparam *)d;
+ m = ip6cp->ip6c_m;
+ ip6 = ip6cp->ip6c_ip6;
+ off = ip6cp->ip6c_off;
+ } else {
+ m = NULL;
+ ip6 = NULL;
+ }
+
/* translate addresses into internal form */
sa6 = *(struct sockaddr_in6 *)sa;
if (IN6_IS_ADDR_LINKLOCAL(&sa6.sin6_addr))
@@ -391,8 +391,7 @@ int tcp6_attach __P((struct socket *));
void tcp6_canceltimers __P((struct tcp6cb *));
struct tcp6cb *
tcp6_close __P((struct tcp6cb *));
-void tcp6_ctlinput __P((int, struct sockaddr *, struct ip6_hdr *,
- struct mbuf *, int));
+void tcp6_ctlinput __P((int, struct sockaddr *, void *));
int tcp6_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
struct tcp6cb *
tcp6_disconnect __P((struct tcp6cb *));
@@ -97,6 +97,7 @@
#include <netinet6/ip6_var.h>
#include <netinet6/icmp6.h>
#include <netinet6/udp6_var.h>
+#include <netinet6/ip6protosw.h>
#ifdef IPSEC
#include <netinet6/ipsec.h>
@@ -473,29 +474,42 @@ udp6_notify(in6p, errno)
}
void
-udp6_ctlinput(cmd, sa, ip6, m, off)
+udp6_ctlinput(cmd, sa, d)
int cmd;
struct sockaddr *sa;
- register struct ip6_hdr *ip6;
- struct mbuf *m;
- int off;
+ void *d;
{
register struct udphdr *uhp;
struct udphdr uh;
struct sockaddr_in6 sa6;
+ register struct ip6_hdr *ip6;
+ struct mbuf *m;
+ int off;
if (sa->sa_family != AF_INET6 ||
sa->sa_len != sizeof(struct sockaddr_in6))
return;
+
#if 0
if (cmd == PRC_IFNEWADDR)
in6_mrejoin(&udb6);
- else
+ } else
#endif
if (!PRC_IS_REDIRECT(cmd) &&
((unsigned)cmd >= PRC_NCMDS || inet6ctlerrmap[cmd] == 0))
return;
+ /* if the parameter is from icmp6, decode it. */
+ if (d != NULL) {
+ struct ip6ctlparam *ip6cp = (struct ip6ctlparam *)d;
+ m = ip6cp->ip6c_m;
+ ip6 = ip6cp->ip6c_ip6;
+ off = ip6cp->ip6c_off;
+ } else {
+ m = NULL;
+ ip6 = NULL;
+ }
+
/* translate addresses into internal form */
sa6 = *(struct sockaddr_in6 *)sa;
if (IN6_IS_ADDR_LINKLOCAL(&sa6.sin6_addr))
@@ -151,8 +151,7 @@ struct udp6stat {
struct in6pcb udb6;
struct udp6stat udp6stat;
-void udp6_ctlinput __P((int, struct sockaddr *, struct ip6_hdr *,
- struct mbuf *, int));
+void udp6_ctlinput __P((int, struct sockaddr *, void *));
void udp6_init __P((void));
int udp6_input __P((struct mbuf **, int *, int));
int udp6_output __P((struct in6pcb *,
@@ -139,6 +139,7 @@
#include <netinet6/in6_pcb.h>
#include <netinet6/ip6_var.h>
#include <netinet6/in6_var.h>
+#include <netinet6/ip6protosw.h>
#endif
#include <netinet/tcp.h>
@@ -1055,36 +1056,54 @@ tcp6_notify(in6p, error)
#if defined(INET6) && !defined(TCP6)
void
-tcp6_ctlinput(cmd, sa, ip6, m, off)
+tcp6_ctlinput(cmd, sa, d)
int cmd;
struct sockaddr *sa;
- register struct ip6_hdr *ip6;
- struct mbuf *m;
- int off;
+ void *d;
{
register struct tcphdr *thp;
struct tcphdr th;
void (*notify) __P((struct in6pcb *, int)) = tcp6_notify;
int nmatch;
extern struct in6_addr zeroin6_addr; /* netinet6/in6_pcb.c */
struct sockaddr_in6 sa6;
+ register struct ip6_hdr *ip6;
+ struct mbuf *m;
+ int off;
if (sa->sa_family != AF_INET6 ||
sa->sa_len != sizeof(struct sockaddr_in6))
return;
- if (cmd == PRC_QUENCH)
+ if ((unsigned)cmd >= PRC_NCMDS)
+ return;
+ else if (cmd == PRC_QUENCH) {
+ /* XXX there's no PRC_QUENCH in IPv6 */
notify = tcp6_quench;
+ } else if (PRC_IS_REDIRECT(cmd))
+ notify = in6_rtchange, d = NULL;
else if (cmd == PRC_MSGSIZE)
- notify = tcp6_mtudisc;
- else if (!PRC_IS_REDIRECT(cmd) &&
- ((unsigned)cmd > PRC_NCMDS || inet6ctlerrmap[cmd] == 0))
+ notify = tcp6_mtudisc, d = NULL;
+ else if (cmd == PRC_HOSTDEAD)
+ d = NULL;
+ else if (inet6ctlerrmap[cmd] == 0)
return;
/* translate addresses into internal form */
sa6 = *(struct sockaddr_in6 *)sa;
if (IN6_IS_ADDR_LINKLOCAL(&sa6.sin6_addr))
sa6.sin6_addr.s6_addr16[1] = htons(m->m_pkthdr.rcvif->if_index);
+ /* if the parameter is from icmp6, decode it. */
+ if (d != NULL) {
+ struct ip6ctlparam *ip6cp = (struct ip6ctlparam *)d;
+ m = ip6cp->ip6c_m;
+ ip6 = ip6cp->ip6c_ip6;
+ off = ip6cp->ip6c_off;
+ } else {
+ m = NULL;
+ ip6 = NULL;
+ }
+
if (ip6) {
/*
* XXX: We assume that when ip6 is non NULL,
@@ -617,8 +617,7 @@ void tcp_canceltimers __P((struct tcpcb *));
struct tcpcb *
tcp_close __P((struct tcpcb *));
#if defined(INET6) && !defined(TCP6)
-void tcp6_ctlinput __P((int, struct sockaddr *, struct ip6_hdr *,
- struct mbuf *, int));
+void tcp6_ctlinput __P((int, struct sockaddr *, void *));
#endif
void *tcp_ctlinput __P((int, struct sockaddr *, void *));
int tcp_ctloutput __P((int, struct socket *, int, int, struct mbuf **));

0 comments on commit f0644f1

Please sign in to comment.