-/* $OpenBSD: pipex.c,v 1.66 2015/03/18 12:23:15 dlg Exp $ */
+/* $OpenBSD: pipex.c,v 1.67 2015/04/10 11:02:12 dlg Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
/* pipex traffic queue */
struct ifqueue pipexinq;
struct ifqueue pipexoutq;
-struct pipex_tag {
- struct pipex_session *session;
- int proto;
-};
void *pipex_softintr = NULL;
Static void pipex_softintr_handler(void *);
+/* borrow an mbuf pkthdr field */
+#define ph_ppp_proto ether_vtag
+
/* from udp_usrreq.c */
extern int udpcksum;
Static void
pipex_ppp_dequeue(void)
{
+ struct pipex_session *pkt_session;
+ u_int16_t proto;
struct mbuf *m;
- struct m_tag *mtag;
- struct pipex_tag *tag;
int c, s;
/* ppp output */
}
splx(s);
- mtag = m_tag_find(m, PACKET_TAG_PIPEX, NULL);
- if (mtag == NULL) {
+ pkt_session = m->m_pkthdr.ph_cookie;
+ if (pkt_session == NULL) {
m_freem(m);
continue;
}
- tag = (struct pipex_tag *)(mtag + 1);
- if (tag->session->is_multicast != 0) {
+ proto = m->m_pkthdr.ph_ppp_proto;
+
+ m->m_pkthdr.ph_cookie = NULL;
+ m->m_pkthdr.ph_ppp_proto = 0;
+
+ if (pkt_session->is_multicast != 0) {
struct pipex_session *session;
struct mbuf *m0;
LIST_FOREACH(session, &pipex_session_list,
session_list) {
if (session->pipex_iface !=
- tag->session->pipex_iface)
+ pkt_session->pipex_iface)
continue;
if (session->ip_forward == 0 &&
session->ip6_forward == 0)
session->stat.oerrors++;
continue;
}
- pipex_ppp_output(m0, session, tag->proto);
+ pipex_ppp_output(m0, session, proto);
}
m_freem(m);
} else
- pipex_ppp_output(m, tag->session, tag->proto);
+ pipex_ppp_output(m, pkt_session, proto);
}
/* ppp input */
}
splx(s);
- mtag = m_tag_find(m, PACKET_TAG_PIPEX, NULL);
- if (mtag == NULL) {
+ pkt_session = m->m_pkthdr.ph_cookie;
+ if (pkt_session == NULL) {
m_freem(m);
continue;
}
- tag = (struct pipex_tag *)(mtag + 1);
- pipex_ppp_input(m, tag->session, 0);
+ pipex_ppp_input(m, pkt_session, 0);
}
/*
pipex_ppp_enqueue(struct mbuf *m0, struct pipex_session *session,
struct ifqueue *queue)
{
- struct pipex_tag *tag;
- struct m_tag *mtag;
int s;
+ m0->m_pkthdr.ph_cookie = session;
+ /* XXX need to support other protocols */
+ m0->m_pkthdr.ph_ppp_proto = PPP_IP;
+
s = splnet();
if (IF_QFULL(queue)) {
IF_DROP(queue);
splx(s);
goto fail;
}
- mtag = m_tag_get(PACKET_TAG_PIPEX, sizeof(struct pipex_tag), M_NOWAIT);
- if (mtag == NULL) {
- splx(s);
- goto fail;
- }
- m_tag_prepend(m0, mtag);
- tag = (struct pipex_tag *)(mtag + 1);
- tag->session = session;
- tag->proto = PPP_IP; /* XXX need to support other protocols */
-
IF_ENQUEUE(queue, m0);
splx(s);
{
struct pipex_session *session;
struct ip ip;
- struct pipex_tag *tag;
- struct m_tag *mtag;
struct mbuf *mret;
session = NULL;
session = pipex_lookup_by_ip_address(ip.ip_dst);
}
if (session != NULL) {
- for (mtag = m_tag_find(m0, PACKET_TAG_PIPEX, NULL);
- mtag != NULL;
- mtag = m_tag_find(m0, PACKET_TAG_PIPEX, mtag)) {
- tag = (struct pipex_tag *)(mtag + 1);
- if (tag->session == session) {
- /*
- * Don't encapsulate encapsulated
- * packets.
- */
- m_freem(m0);
- return (NULL);
- }
- }
-
if (session == pipex_iface->multicast_session) {
mret = m0;
m0 = m_copym(m0, 0, M_COPYALL, M_NOWAIT);
pipex_ppp_input(struct mbuf *m0, struct pipex_session *session, int decrypted)
{
int proto, hlen = 0;
- struct m_tag *mtag;
- struct pipex_tag *tag;
KASSERT(m0->m_pkthdr.len >= PIPEX_PPPMINLEN);
proto = pipex_ppp_proto(m0, session, 0, &hlen);
return;
}
#endif
- /* delete mtag from decapsulated packet */
- for (mtag = m_tag_find(m0, PACKET_TAG_PIPEX, NULL); mtag;
- mtag = m_tag_find(m0, PACKET_TAG_PIPEX, mtag)) {
- tag = (struct pipex_tag *)(mtag + 1);
- if (tag->session == session) {
- m_tag_delete(m0, mtag);
- break;
- }
- }
-
switch (proto) {
case PPP_IP:
if (session->ip_forward == 0)
-/* $OpenBSD: mbuf.h,v 1.187 2015/02/10 03:46:30 lteo Exp $ */
+/* $OpenBSD: mbuf.h,v 1.188 2015/04/10 11:02:12 dlg Exp $ */
/* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */
/*
#define PACKET_TAG_GRE 0x0080 /* GRE processing done */
#define PACKET_TAG_DLT 0x0100 /* data link layer type */
#define PACKET_TAG_PF_DIVERT 0x0200 /* pf(4) diverted packet */
-#define PACKET_TAG_PIPEX 0x0400 /* pipex session cache */
#define PACKET_TAG_PF_REASSEMBLED 0x0800 /* pf reassembled ipv6 packet */
#define PACKET_TAG_SRCROUTE 0x1000 /* IPv4 source routing options */
#define PACKET_TAG_TUNNEL 0x2000 /* Tunnel endpoint address */
#define MTAG_BITS \
("\20\1IPSEC_IN_DONE\2IPSEC_OUT_DONE\3IPSEC_IN_CRYPTO_DONE" \
"\4IPSEC_OUT_CRYPTO_NEEDED\5IPSEC_PENDING_TDB\6BRIDGE\7GIF\10GRE\11DLT" \
- "\12PF_DIVERT\13PIPEX\14PF_REASSEMBLED\15SRCROUTE\16TUNNEL")
+ "\12PF_DIVERT\14PF_REASSEMBLED\15SRCROUTE\16TUNNEL")
/*
* Maximum tag payload length (that is excluding the m_tag structure).