Skip to content

Commit

Permalink
Attempt to intercpt packets at if_output()
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Jul 26, 2018
1 parent ebc4de0 commit cdb6b8e
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 15 deletions.
2 changes: 1 addition & 1 deletion sys/kern/kern_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ thread_exit(void)
KASSERT(TAILQ_EMPTY(&td->td_sigqueue.sq_list), ("signal pending"));

#ifdef PSPAT
exit_pspat();
// exit_pspat();
#endif

#ifdef AUDIT
Expand Down
1 change: 1 addition & 0 deletions sys/net/bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,7 @@ bpfwrite(struct cdev *dev, struct uio *uio, int ioflag)
ro.ro_flags = RT_HAS_HEADER;
}

printf("bpf.c line 1192\n");
error = (*ifp->if_output)(ifp, m, &dst, &ro);
if (error)
counter_u64_add(d->bd_wdcount, 1);
Expand Down
21 changes: 17 additions & 4 deletions sys/net/pspat/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ pspat_arb_prefetch(struct pspat *arb, struct pspat_queue *pq)
static int
pspat_arb_dispatch(struct pspat *arb, struct mbuf *mbf)
{
printf("Inside arb_dispatch with packet %d\n", (int) mbf);
struct pspat_dispatcher s = arb->dispatchers[0];
int err;

Expand Down Expand Up @@ -226,8 +227,11 @@ pspat_arb_drain(struct pspat *arb, struct pspat_queue *pq)
static void
pspat_txqs_flush(struct mbuf *m)
{
dummynet_send(m);
// struct ifnet *ifp = m->ifp;
// dummynet_send(m);
struct ifnet *ifp = m->ifp;
printf("Sending packet %d out\n", (int) m);
(*ifp->if_output)(ifp, m, m->gw, m->ro);
printf("Sent packet out\n");
// ether_output_frame(ifp, m);
// ip_output(m, NULL, NULL, IP_FORWARDING, NULL, NULL);
}
Expand All @@ -236,6 +240,7 @@ pspat_txqs_flush(struct mbuf *m)
int
pspat_do_arbiter(struct pspat *arb)
{
printf("Inside Arbiter\n");
int i;
struct timespec ts;
nanotime(&ts);
Expand Down Expand Up @@ -272,6 +277,7 @@ pspat_do_arbiter(struct pspat *arb)
pspat_arb_prefetch(arb, (i + 1 < arb->n_queues ? pq + 1 : arb->queues));

while ( (mbf = pspat_arb_get_mbf(arb, pq)) ) {
printf("Arbter sending packet %d to dispatch\n", (int) mbf);
pspat_arb_dispatch(arb, mbf);

empty = false;
Expand Down Expand Up @@ -299,6 +305,7 @@ pspat_do_arbiter(struct pspat *arb)
while (link_idle < now && ndeq < pspat_arb_batch) {
if ((mbf = pspat_mb_extract(m)) != NULL) {
link_idle += picos_per_byte * mbf->m_len;
printf("Arbiter sending packet %d to TXQ\n", (int) mbf);
pspat_txqs_flush(mbf);
ndeq ++;
} else {
Expand Down Expand Up @@ -354,11 +361,14 @@ pspat_shutdown(struct pspat *arb)
printf("%s: CMs drained, found %d mbfs\n", __func__, n);
}

extern int pspat_client_handler(struct mbuf *mbuf, struct ifnet *ifp);
extern int pspat_client_handler(struct mbuf *mbuf, struct ifnet *ifp,
const struct sockaddr *gw, struct route *ro);

int
pspat_client_handler(struct mbuf *mbf, struct ifnet *ifp)
pspat_client_handler(struct mbuf *mbf, struct ifnet *ifp,
const struct sockaddr *gw, struct route *ro)
{
printf("Inside pspat_client_handler() with packet %d\n", (int) mbf);
static struct mbuf *ins_mbf;

if(mbf == ins_mbf) {
Expand All @@ -383,8 +393,11 @@ pspat_client_handler(struct mbuf *mbf, struct ifnet *ifp)
cpu = curthread->td_oncpu;
mbf->sender_cpu = cpu;
mbf->ifp = ifp;
mbf->gw = gw;
mbf->ro = ro;

pq = arb->queues + cpu;
printf("pspat_client_handler sending packet %d to cli_push\n", (int) mbf);
if (pspat_cli_push(pq, mbf)) {
pspat_stats[cpu].inq_drop++;
rc = 1;
Expand Down
3 changes: 2 additions & 1 deletion sys/net/pspat/pspat.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ extern struct rwlock pspat_rwlock;

int pspat_do_arbiter(struct pspat *arb);

int pspat_client_handler(struct mbuf *mbf, struct ifnet *ifp);
int pspat_client_handler(struct mbuf *mbf, struct ifnet *ifp,
const struct sockaddr *gw, struct route *ro);

void pspat_shutdown(struct pspat *arb);

Expand Down
3 changes: 3 additions & 0 deletions sys/netinet/if_ether.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ arprequest(struct ifnet *ifp, const struct in_addr *sip,

m->m_flags |= M_BCAST;
m_clrprotoflags(m); /* Avoid confusing lower layers. */
printf("if_ether.c line 428\n");
(*ifp->if_output)(ifp, m, &sa, &ro);
ARPSTAT_INC(txrequests);
}
Expand Down Expand Up @@ -1132,6 +1133,7 @@ in_arpinput(struct mbuf *m)
ro.ro_flags = 0;

m_clrprotoflags(m); /* Avoid confusing lower layers. */
printf("if_ether.c line 1135\n");
(*ifp->if_output)(ifp, m, &sa, &ro);
ARPSTAT_INC(txreplies);
return;
Expand Down Expand Up @@ -1233,6 +1235,7 @@ arp_check_update_lle(struct arphdr *ah, struct in_addr isaddr, struct ifnet *ifp
m_hold->m_nextpkt = NULL;
/* Avoid confusing lower layers. */
m_clrprotoflags(m_hold);
printf("if_ether.c line 1236\n");
(*ifp->if_output)(ifp, m_hold, &sa, NULL);
}
} else
Expand Down
2 changes: 2 additions & 0 deletions sys/netinet/ip_fastfwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ ip_tryforward(struct mbuf *m)
* Send off the packet via outgoing interface
*/
IP_PROBE(send, NULL, NULL, ip, nh.nh_ifp, ip, NULL);
printf("ip_fastfwd.c line 373\n");
error = (*nh.nh_ifp->if_output)(nh.nh_ifp, m,
(struct sockaddr *)&dst, NULL);
} else {
Expand Down Expand Up @@ -406,6 +407,7 @@ ip_tryforward(struct mbuf *m)
mtod(m, struct ip *), nh.nh_ifp,
mtod(m, struct ip *), NULL);
/* XXX: we can use cached route here */
printf("ip_fastfwd.c line 409\n");
error = (*nh.nh_ifp->if_output)(nh.nh_ifp, m,
(struct sockaddr *)&dst, NULL);
if (error)
Expand Down
21 changes: 19 additions & 2 deletions sys/netinet/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ ip_output_pfil(struct mbuf **mp, struct ifnet *ifp, struct inpcb *inp,

return 0;
}
#ifdef PSPAT
extern int pspat_enable;
extern int pspat_client_handler(struct mbuf *mbf, struct ifnet *ifp,
const struct sockaddr *gw, struct route *ro);
#endif

/*
* IP output. The packet in mbuf chain m contains a skeletal IP
Expand Down Expand Up @@ -659,8 +664,19 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags,
m->m_pkthdr.snd_tag = NULL;
}
#endif
error = (*ifp->if_output)(ifp, m,
(const struct sockaddr *)gw, ro);
#ifdef PSPAT
if(pspat_enable) {
printf("Sending packet %d to PSPAT\n", (int) m);
error = pspat_client_handler(m, ifp,
(const struct sockaddr *)gw, ro);
} else
#endif
{
printf("Normal if_output call\n");
error = (*ifp->if_output)(ifp, m,
(const struct sockaddr *)gw, ro);
}

#ifdef RATELIMIT
/* check for route change */
if (error == EAGAIN)
Expand Down Expand Up @@ -711,6 +727,7 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags,
m->m_pkthdr.snd_tag = NULL;
}
#endif
printf("ip_output.c line 714\n");
error = (*ifp->if_output)(ifp, m,
(const struct sockaddr *)gw, ro);
#ifdef RATELIMIT
Expand Down
1 change: 1 addition & 0 deletions sys/netinet6/ip6_fastfwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ ip6_tryforward(struct mbuf *m)
if (IN6_IS_SCOPE_LINKLOCAL(&dst.sin6_addr))
dst.sin6_addr.s6_addr16[1] = htons(nh.nh_ifp->if_index & 0xffff);

printf("ip6_fastfwd.c line 285\n");
error = (*nh.nh_ifp->if_output)(nh.nh_ifp, m,
(struct sockaddr *)&dst, NULL);
if (error != 0) {
Expand Down
1 change: 1 addition & 0 deletions sys/netinet6/ip6_mroute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,7 @@ phyint_send(struct ip6_hdr *ip6, struct mif6 *mifp, struct mbuf *m)
* we need no ND for a multicast forwarded packet...right?
*/
m_clrprotoflags(m); /* Avoid confusing lower layers. */
printf("ip6+mroute.c line 1611\n");
error = (*ifp->if_output)(ifp, mb_copy,
(struct sockaddr *)&dst6, NULL);
MRT6_DLOG(DEBUG_XMIT, "mif %u err %d",
Expand Down
1 change: 1 addition & 0 deletions sys/netinet6/nd6.c
Original file line number Diff line number Diff line change
Expand Up @@ -2220,6 +2220,7 @@ nd6_output_ifp(struct ifnet *ifp, struct ifnet *origifp, struct mbuf *m,
if ((ifp->if_flags & IFF_LOOPBACK) == 0)
origifp = ifp;

printf("nd6.c line 2223\n");
error = (*ifp->if_output)(origifp, m, (struct sockaddr *)dst, ro);
return (error);
}
Expand Down
1 change: 1 addition & 0 deletions sys/netinet6/send.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ send_output(struct mbuf *m, struct ifnet *ifp, int direction)
* if now needed?
*/
int error;
printf("send.c line 200\n");
error = ((*ifp->if_output)(ifp, m, (struct sockaddr *)&dst,
NULL));
if (error)
Expand Down
14 changes: 7 additions & 7 deletions sys/netpfil/ipfw/ip_dn_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,17 +881,17 @@ dummynet_io(struct mbuf **m0, int dir, struct ip_fw_args *fwa)
if (tag_mbuf(m, dir, fwa))
goto dropit;
#ifdef PSPAT
if (pspat_enable)
{
// if (pspat_enable)
// {
// if (dir == (DIR_OUT | PROTO_LAYER2)) {
// int ret = pspat_client_handler(m, fwa->oif);
// return ret;
// }
if (dir == DIR_OUT) {
int ret = pspat_client_handler(m, fwa->oif);
return ret;
}
}
// if (dir == DIR_OUT) {
// int ret = pspat_client_handler(m, fwa->oif);
// return ret;
// }
// }
#endif
if (dn_cfg.busy) {
/* if the upper half is busy doing something expensive,
Expand Down
2 changes: 2 additions & 0 deletions sys/netpfil/ipfw/nat64/nat64_translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ nat64_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,

if (logdata != NULL)
nat64_log(logdata, m, dst->sa_family);
printf("nat_tranclate.c line 97\n");
error = (*ifp->if_output)(ifp, m, dst, NULL);
if (error != 0)
NAT64STAT_INC(stats, oerrors);
Expand Down Expand Up @@ -148,6 +149,7 @@ nat64_output_one(struct mbuf *m, struct nat64_counters *stats, void *logdata)
}
if (logdata != NULL)
nat64_log(logdata, m, dst->sa_family);
printf("nat_translate.c line 151\n");
error = (*ifp->if_output)(ifp, m, dst, NULL);
if (error != 0)
NAT64STAT_INC(stats, oerrors);
Expand Down
2 changes: 2 additions & 0 deletions sys/netpfil/pf/pf.c
Original file line number Diff line number Diff line change
Expand Up @@ -5553,6 +5553,7 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp,
m0->m_pkthdr.csum_flags &= ~CSUM_IP;
}
m_clrprotoflags(m0); /* Avoid confusing lower layers. */
printf("pf.c line 5556\n");
error = (*ifp->if_output)(ifp, m0, sintosa(&dst), NULL);
goto done;
}
Expand All @@ -5578,6 +5579,7 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp,
m0->m_nextpkt = NULL;
if (error == 0) {
m_clrprotoflags(m0);
printf("pf.c line 5581\n");
error = (*ifp->if_output)(ifp, m0, sintosa(&dst), NULL);
} else
m_freem(m0);
Expand Down
2 changes: 2 additions & 0 deletions sys/sys/mbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ struct mbuf {
};
#ifdef PSPAT
struct ifnet *ifp;
const struct sockaddr *gw;
struct route *ro;
int sender_cpu;
#endif
};
Expand Down

0 comments on commit cdb6b8e

Please sign in to comment.