Hi,
To hide pf internals move code from in_ouraddr() to pf_ouraddr().
This will also make it possible to implement the same shortcut for
IPv6.
ok?
bluhm
Index: net/pf.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/net/pf.c,v
retrieving revision 1.978
diff -u -p -r1.978 pf.c
--- net/pf.c21 Jun 2016 16:45:37 - 1.978
+++ net/pf.c18 Jul 2016 08:30:49 -
@@ -6761,6 +6761,27 @@ pf_cksum(struct pf_pdesc *pd, struct mbu
}
}
+int
+pf_ouraddr(struct mbuf *m)
+{
+ struct pf_state_key *sk;
+
+ if (m->m_pkthdr.pf.flags & PF_TAG_DIVERTED)
+ return (1);
+
+ sk = m->m_pkthdr.pf.statekey;
+ if (sk != NULL) {
+ if (sk->inp != NULL)
+ return (1);
+
+ /* If we have linked state keys it is certainly forwarded. */
+ if (sk->reverse != NULL)
+ return (0);
+ }
+
+ return (-1);
+}
+
/*
* must be called whenever any addressing information such as
* address, port, protocol has changed
Index: net/pfvar.h
===
RCS file: /data/mirror/openbsd/cvs/src/sys/net/pfvar.h,v
retrieving revision 1.431
diff -u -p -r1.431 pfvar.h
--- net/pfvar.h 29 Mar 2016 10:34:42 - 1.431
+++ net/pfvar.h 18 Jul 2016 08:30:49 -
@@ -1763,6 +1763,7 @@ int pf_rtlabel_match(struct pf_addr *, s
int);
intpf_socket_lookup(struct pf_pdesc *);
struct pf_state_key *pf_alloc_state_key(int);
+intpf_ouraddr(struct mbuf *);
void pf_pkt_addr_changed(struct mbuf *);
struct inpcb *pf_inp_lookup(struct mbuf *);
void pf_inp_link(struct mbuf *, struct inpcb *);
Index: netinet/ip_input.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_input.c,v
retrieving revision 1.277
diff -u -p -r1.277 ip_input.c
--- netinet/ip_input.c 18 Jun 2016 10:36:13 - 1.277
+++ netinet/ip_input.c 18 Jul 2016 08:30:49 -
@@ -592,20 +592,16 @@ in_ouraddr(struct mbuf *m, struct ifnet
struct ip *ip;
struct sockaddr_in sin;
int match = 0;
-#if NPF > 0
- struct pf_state_key *key;
- if (m->m_pkthdr.pf.flags & PF_TAG_DIVERTED)
+#if NPF > 0
+ switch (pf_ouraddr(m)) {
+ case 0:
+ return (0);
+ case 1:
return (1);
-
- key = m->m_pkthdr.pf.statekey;
- if (key != NULL) {
- if (key->inp != NULL)
- return (1);
-
- /* If we have linked state keys it is certainly forwarded. */
- if (key->reverse != NULL)
- return (0);
+ default:
+ /* pf does not know it */
+ break;
}
#endif