Commit 6ec65e49 authored by Brenden Blanco's avatar Brenden Blanco

Drop PROTO macro syntax and introduce alternative

* Feedback given by some external users was that the PROTO syntax was
  opaque and unintuitive. As such, drop that macro and introduce an
  alternative syntax.
* Convert all to use 'cursor_advance' macro API
Signed-off-by: default avatarBrenden Blanco <bblanco@plumgrid.com>
parent 307fff0f
...@@ -19,14 +19,16 @@ int pass(struct __sk_buff *skb) { ...@@ -19,14 +19,16 @@ int pass(struct __sk_buff *skb) {
// returns: > 0 when an IP is known // returns: > 0 when an IP is known
// = 0 when an IP is not known, or non-IP traffic // = 0 when an IP is not known, or non-IP traffic
int classify_wan(struct __sk_buff *skb) { int classify_wan(struct __sk_buff *skb) {
BEGIN(ethernet); u8 *cursor = 0;
PROTO(ethernet) { ethernet: {
struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
switch (ethernet->type) { switch (ethernet->type) {
case 0x0800: goto ip; case ETH_P_IP: goto ip;
default: goto EOP;
} }
goto EOP;
} }
PROTO(ip) { ip: {
struct ip_t *ip = cursor_advance(cursor, sizeof(*ip));
u32 dip = ip->dst; u32 dip = ip->dst;
struct ipkey key = {.client_ip=dip}; struct ipkey key = {.client_ip=dip};
int *val = learned_ips.lookup(&key); int *val = learned_ips.lookup(&key);
...@@ -42,14 +44,16 @@ EOP: ...@@ -42,14 +44,16 @@ EOP:
// Mark the inserted entry with a non-zero value to be used by the classify_wan // Mark the inserted entry with a non-zero value to be used by the classify_wan
// lookup. // lookup.
int classify_neighbor(struct __sk_buff *skb) { int classify_neighbor(struct __sk_buff *skb) {
BEGIN(ethernet); u8 *cursor = 0;
PROTO(ethernet) { ethernet: {
struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
switch (ethernet->type) { switch (ethernet->type) {
case 0x0800: goto ip; case ETH_P_IP: goto ip;
default: goto EOP;
} }
goto EOP;
} }
PROTO(ip) { ip: {
struct ip_t *ip = cursor_advance(cursor, sizeof(*ip));
u32 sip = ip->src; u32 sip = ip->src;
struct ipkey key = {.client_ip=sip}; struct ipkey key = {.client_ip=sip};
int val = 1; int val = 1;
......
...@@ -57,37 +57,43 @@ int handle_egress(struct __sk_buff *skb) { ...@@ -57,37 +57,43 @@ int handle_egress(struct __sk_buff *skb) {
// parse the outer vxlan frame // parse the outer vxlan frame
int handle_outer(struct __sk_buff *skb) { int handle_outer(struct __sk_buff *skb) {
BEGIN(ethernet); u8 *skb_cursor = 0;
PROTO(ethernet) {
// filter bcast/mcast from the stats struct ethernet_t *ethernet = bpf_consume_skb(skb_cursor, sizeof(*ethernet));
if (ethernet->dst & (1ull << 40))
return 1; // filter bcast/mcast from the stats
switch (ethernet->type) { if (ethernet->dst & (1ull << 40))
case 0x0800: goto ip; goto finish;
}
goto EOP; switch (ethernet->type) {
} case 0x0800: goto ip;
PROTO(ip) { default: goto finish;
skb->cb[CB_SIP] = ip->src;
skb->cb[CB_DIP] = ip->dst;
switch (ip->nextp) {
case 17: goto udp;
}
goto EOP;
} }
PROTO(udp) {
switch (udp->dport) { ip: ;
case 4789: goto vxlan; struct ip_t *ip = bpf_consume_skb(skb_cursor, sizeof(*ip));
} skb->cb[CB_SIP] = ip->src;
goto EOP; skb->cb[CB_DIP] = ip->dst;
switch (ip->nextp) {
case 17: goto udp;
default: goto finish;
} }
PROTO(vxlan) {
skb->cb[CB_VNI] = vxlan->key; udp: ;
skb->cb[CB_OFFSET] = (u64)vxlan + sizeof(*vxlan); struct udp_t *udp = bpf_consume_skb(skb_cursor, sizeof(*udp));
parser.call(skb, 2); switch (udp->dport) {
goto EOP; case 4789: goto vxlan;
default: goto finish;
} }
EOP:
vxlan: ;
struct vxlan_t *vxlan = bpf_consume_skb(skb_cursor, sizeof(*vxlan));
skb->cb[CB_VNI] = vxlan->key;
skb->cb[CB_OFFSET] = (u64)vxlan + sizeof(*vxlan);
parser.call(skb, 2);
finish:
return 1; return 1;
} }
...@@ -100,19 +106,19 @@ int handle_inner(struct __sk_buff *skb) { ...@@ -100,19 +106,19 @@ int handle_inner(struct __sk_buff *skb) {
.outer_sip = skb->cb[CB_SIP], .outer_sip = skb->cb[CB_SIP],
.outer_dip = skb->cb[CB_DIP] .outer_dip = skb->cb[CB_DIP]
}; };
BEGIN_OFFSET(ethernet, skb->cb[CB_OFFSET]); u8 *skb_cursor = (u8 *)(u64)skb->cb[CB_OFFSET];
PROTO(ethernet) {
switch (ethernet->type) { struct ethernet_t *ethernet = bpf_consume_skb(skb_cursor, sizeof(*ethernet));
case 0x0800: goto ip; switch (ethernet->type) {
} case 0x0800: goto ip;
goto EOP; default: goto finish;
}
PROTO(ip) {
key.inner_sip = ip->src;
key.inner_dip = ip->dst;
goto EOP;
} }
EOP: ip: ;
struct ip_t *ip = bpf_consume_skb(skb_cursor, sizeof(*ip));
key.inner_sip = ip->src;
key.inner_dip = ip->dst;
finish:
// consistent ordering // consistent ordering
if (key.outer_dip < key.outer_sip) if (key.outer_dip < key.outer_sip)
swap_ipkey(&key); swap_ipkey(&key);
......
...@@ -16,8 +16,9 @@ BPF_TABLE("hash", int, struct ifindex_leaf_t, egress, 4096); ...@@ -16,8 +16,9 @@ BPF_TABLE("hash", int, struct ifindex_leaf_t, egress, 4096);
BPF_TABLE("hash", u64, struct ifindex_leaf_t, ingress, 4096); BPF_TABLE("hash", u64, struct ifindex_leaf_t, ingress, 4096);
int handle_phys2virt(struct __sk_buff *skb) { int handle_phys2virt(struct __sk_buff *skb) {
BEGIN(ethernet); u8 *cursor = 0;
PROTO(ethernet) { ethernet: {
struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
u64 src_mac = ethernet->src; u64 src_mac = ethernet->src;
struct ifindex_leaf_t *leaf = ingress.lookup(&src_mac); struct ifindex_leaf_t *leaf = ingress.lookup(&src_mac);
if (leaf) { if (leaf) {
...@@ -33,13 +34,13 @@ int handle_phys2virt(struct __sk_buff *skb) { ...@@ -33,13 +34,13 @@ int handle_phys2virt(struct __sk_buff *skb) {
bpf_clone_redirect(skb, leaf->out_ifindex, 0); bpf_clone_redirect(skb, leaf->out_ifindex, 0);
} }
} }
EOP:
return 1; return 1;
} }
int handle_virt2phys(struct __sk_buff *skb) { int handle_virt2phys(struct __sk_buff *skb) {
BEGIN(ethernet); u8 *cursor = 0;
PROTO(ethernet) { ethernet: {
struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
int src_ifindex = skb->ifindex; int src_ifindex = skb->ifindex;
struct ifindex_leaf_t *leaf = egress.lookup(&src_ifindex); struct ifindex_leaf_t *leaf = egress.lookup(&src_ifindex);
if (leaf) { if (leaf) {
...@@ -48,6 +49,5 @@ int handle_virt2phys(struct __sk_buff *skb) { ...@@ -48,6 +49,5 @@ int handle_virt2phys(struct __sk_buff *skb) {
bpf_clone_redirect(skb, leaf->out_ifindex, 0); bpf_clone_redirect(skb, leaf->out_ifindex, 0);
} }
} }
EOP:
return 1; return 1;
} }
...@@ -381,6 +381,18 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) { ...@@ -381,6 +381,18 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) {
return false; return false;
} }
tables_[Decl->getName()] = std::move(table); tables_[Decl->getName()] = std::move(table);
} else if (const PointerType *P = Decl->getType()->getAs<PointerType>()) {
// if var is a pointer to a packet type, clone the annotation into the var
// decl so that the packet dext/dins rewriter can catch it
if (const RecordType *RT = P->getPointeeType()->getAs<RecordType>()) {
if (const RecordDecl *RD = RT->getDecl()->getDefinition()) {
if (DeprecatedAttr *DA = RD->getAttr<DeprecatedAttr>()) {
if (DA->getMessage() == "packet") {
Decl->addAttr(DA->clone(C));
}
}
}
}
} }
return true; return true;
} }
......
...@@ -42,18 +42,8 @@ __attribute__((section("maps/" _table_type))) \ ...@@ -42,18 +42,8 @@ __attribute__((section("maps/" _table_type))) \
struct _name##_table_t _name struct _name##_table_t _name
// packet parsing state machine helpers // packet parsing state machine helpers
#define BEGIN(next) \ #define cursor_advance(_cursor, _len) \
u64 _parse_cursor = 0; \ ({ void *_tmp = _cursor; _cursor += _len; _tmp; })
goto next
#define BEGIN_OFFSET(next, _base_offset) \
u64 _parse_cursor = (_base_offset); \
goto next
#define PROTO(name) \
goto EOP; \
name: ; \
struct name##_t *name __attribute__((deprecated("packet"))) = (void *)_parse_cursor; \
_parse_cursor += sizeof(*name);
char _license[4] SEC("license") = "GPL"; char _license[4] SEC("license") = "GPL";
......
...@@ -14,18 +14,22 @@ ...@@ -14,18 +14,22 @@
* limitations under the License. * limitations under the License.
*/ */
#include <uapi/linux/if_ether.h>
#define BPF_PACKET_HEADER __attribute__((packed)) __attribute__((deprecated("packet")))
struct ethernet_t { struct ethernet_t {
unsigned long long dst:48; unsigned long long dst:48;
unsigned long long src:48; unsigned long long src:48;
unsigned int type:16; unsigned int type:16;
} __attribute__((packed)); } BPF_PACKET_HEADER;
struct dot1q_t { struct dot1q_t {
unsigned short pri:3; unsigned short pri:3;
unsigned short cfi:1; unsigned short cfi:1;
unsigned short vlanid:12; unsigned short vlanid:12;
unsigned short type; unsigned short type;
} __attribute__((packed)); } BPF_PACKET_HEADER;
struct arp_t { struct arp_t {
unsigned short htype; unsigned short htype;
...@@ -37,7 +41,7 @@ struct arp_t { ...@@ -37,7 +41,7 @@ struct arp_t {
unsigned long long spa:32; unsigned long long spa:32;
unsigned long long tha:48; unsigned long long tha:48;
unsigned int tpa; unsigned int tpa;
} __attribute__((packed)); } BPF_PACKET_HEADER;
struct ip_t { struct ip_t {
unsigned char ver:4; // byte 0 unsigned char ver:4; // byte 0
...@@ -54,14 +58,14 @@ struct ip_t { ...@@ -54,14 +58,14 @@ struct ip_t {
unsigned short hchecksum; unsigned short hchecksum;
unsigned int src; // byte 12 unsigned int src; // byte 12
unsigned int dst; // byte 16 unsigned int dst; // byte 16
} __attribute__((packed)); } BPF_PACKET_HEADER;
struct udp_t { struct udp_t {
unsigned short sport; unsigned short sport;
unsigned short dport; unsigned short dport;
unsigned short length; unsigned short length;
unsigned short crc; unsigned short crc;
} __attribute__((packed)); } BPF_PACKET_HEADER;
struct tcp_t { struct tcp_t {
unsigned short src_port; // byte 0 unsigned short src_port; // byte 0
...@@ -81,7 +85,7 @@ struct tcp_t { ...@@ -81,7 +85,7 @@ struct tcp_t {
unsigned short rcv_wnd; unsigned short rcv_wnd;
unsigned short cksum; // byte 16 unsigned short cksum; // byte 16
unsigned short urg_ptr; unsigned short urg_ptr;
} __attribute__((packed)); } BPF_PACKET_HEADER;
struct vxlan_t { struct vxlan_t {
unsigned int rsv1:4; unsigned int rsv1:4;
...@@ -90,4 +94,4 @@ struct vxlan_t { ...@@ -90,4 +94,4 @@ struct vxlan_t {
unsigned int rsv3:24; unsigned int rsv3:24;
unsigned int key:24; unsigned int key:24;
unsigned int rsv4:8; unsigned int rsv4:8;
} __attribute__((packed)); } BPF_PACKET_HEADER;
...@@ -106,6 +106,7 @@ int pem(struct __sk_buff *skb) { ...@@ -106,6 +106,7 @@ int pem(struct __sk_buff *skb) {
static int br_common(struct __sk_buff *skb, int which_br) __attribute__((always_inline)); static int br_common(struct __sk_buff *skb, int which_br) __attribute__((always_inline));
static int br_common(struct __sk_buff *skb, int which_br) { static int br_common(struct __sk_buff *skb, int which_br) {
u8 *cursor = 0;
bpf_metadata_t meta = {}; bpf_metadata_t meta = {};
u16 proto; u16 proto;
u16 arpop; u16 arpop;
...@@ -126,8 +127,8 @@ static int br_common(struct __sk_buff *skb, int which_br) { ...@@ -126,8 +127,8 @@ static int br_common(struct __sk_buff *skb, int which_br) {
meta.rx_port_id = skb->cb[1]; meta.rx_port_id = skb->cb[1];
} }
BEGIN(ethernet); struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
PROTO(ethernet) { {
dmac.addr = ethernet->dst; dmac.addr = ethernet->dst;
if (meta.prog_id != 0) { if (meta.prog_id != 0) {
/* send to the router */ /* send to the router */
...@@ -152,22 +153,24 @@ static int br_common(struct __sk_buff *skb, int which_br) { ...@@ -152,22 +153,24 @@ static int br_common(struct __sk_buff *skb, int which_br) {
} }
switch (ethernet->type) { switch (ethernet->type) {
case 0x0800: goto ip; case ETH_P_IP: goto ip;
case 0x0806: goto arp; case ETH_P_ARP: goto arp;
case 0x8100: goto dot1q; case ETH_P_8021Q: goto dot1q;
default: goto EOP;
} }
goto EOP;
} }
PROTO(dot1q) { dot1q: {
struct dot1q_t *dot1q = cursor_advance(cursor, sizeof(*dot1q));
switch(dot1q->type) { switch(dot1q->type) {
case 0x0806: goto arp; case ETH_P_IP: goto ip;
case 0x0800: goto ip; case ETH_P_ARP: goto arp;
default: goto EOP;
} }
goto EOP;
} }
PROTO(arp) { arp: {
struct arp_t *arp = cursor_advance(cursor, sizeof(*arp));
/* mac learning */ /* mac learning */
arpop = arp->oper; arpop = arp->oper;
if (arpop == 2) { if (arpop == 2) {
...@@ -180,7 +183,7 @@ static int br_common(struct __sk_buff *skb, int which_br) { ...@@ -180,7 +183,7 @@ static int br_common(struct __sk_buff *skb, int which_br) {
__u32 ifindex = *rtrif_p; __u32 ifindex = *rtrif_p;
eth_addr_t smac; eth_addr_t smac;
smac.addr = ethernet->src; smac.addr = ethernet->src;
if (which_br == 1) if (which_br == 1)
br1_mac_ifindex.update(&smac, &ifindex); br1_mac_ifindex.update(&smac, &ifindex);
else else
...@@ -190,7 +193,8 @@ static int br_common(struct __sk_buff *skb, int which_br) { ...@@ -190,7 +193,8 @@ static int br_common(struct __sk_buff *skb, int which_br) {
goto xmit; goto xmit;
} }
PROTO(ip) { ip: {
struct ip_t *ip = cursor_advance(cursor, sizeof(*ip));
goto xmit; goto xmit;
} }
......
...@@ -13,12 +13,10 @@ class TestClang(TestCase): ...@@ -13,12 +13,10 @@ class TestClang(TestCase):
text = """ text = """
#include <bcc/proto.h> #include <bcc/proto.h>
int handle_packet(void *ctx) { int handle_packet(void *ctx) {
BEGIN(ethernet); u8 *cursor = 0;
PROTO(ethernet) { struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
bpf_trace_printk("ethernet->dst = %llx, ethernet->src = %llx\\n", bpf_trace_printk("ethernet->dst = %llx, ethernet->src = %llx\\n",
ethernet->dst, ethernet->src); ethernet->dst, ethernet->src);
}
EOP:
return 0; return 0;
} }
""" """
......
...@@ -42,6 +42,7 @@ BPF_TABLE("hash", struct SlaveKey, struct SlaveLeaf, slave_map, 10); ...@@ -42,6 +42,7 @@ BPF_TABLE("hash", struct SlaveKey, struct SlaveLeaf, slave_map, 10);
int handle_packet(struct __sk_buff *skb) { int handle_packet(struct __sk_buff *skb) {
int ret = 0; int ret = 0;
u8 *cursor = 0;
if (skb->pkt_type == 0) { if (skb->pkt_type == 0) {
// tx // tx
...@@ -70,26 +71,25 @@ int handle_packet(struct __sk_buff *skb) { ...@@ -70,26 +71,25 @@ int handle_packet(struct __sk_buff *skb) {
ret = 0; ret = 0;
} }
BEGIN(ethernet); struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
switch (ethernet->type) {
PROTO(ethernet) { case ETH_P_IP: goto ip;
switch (ethernet->type) { case ETH_P_ARP: goto arp;
case 0x0806: goto arp; case ETH_P_8021Q: goto dot1q;
case 0x0800: goto ip; default: goto EOP;
case 0x8100: goto dot1q;
}
goto EOP;
} }
PROTO(dot1q) { dot1q: {
struct dot1q_t *dot1q = cursor_advance(cursor, sizeof(*dot1q));
switch (dot1q->type) { switch (dot1q->type) {
case 0x0806: goto arp; case ETH_P_IP: goto ip;
case 0x0800: goto ip; case ETH_P_ARP: goto arp;
default: goto EOP;
} }
goto EOP;
} }
PROTO(arp) { arp: {
struct arp_t *arp = cursor_advance(cursor, sizeof(*arp));
if (skb->pkt_type) { if (skb->pkt_type) {
if (arp->oper == 1) { if (arp->oper == 1) {
struct MacaddrKey mac_key = {.ip=arp->spa}; struct MacaddrKey mac_key = {.ip=arp->spa};
...@@ -100,17 +100,20 @@ int handle_packet(struct __sk_buff *skb) { ...@@ -100,17 +100,20 @@ int handle_packet(struct __sk_buff *skb) {
goto EOP; goto EOP;
} }
PROTO(ip) { struct ip_t *ip = cursor_advance(cursor, sizeof(*ip));
ip: {
switch (ip->nextp) { switch (ip->nextp) {
case 6: goto tcp; case 6: goto tcp;
case 17: goto udp; case 17: goto udp;
default: goto EOP;
} }
goto EOP;
} }
PROTO(tcp) { tcp: {
struct tcp_t *tcp = cursor_advance(cursor, sizeof(*tcp));
goto EOP; goto EOP;
} }
PROTO(udp) { udp: {
struct udp_t *udp = cursor_advance(cursor, sizeof(*udp));
if (udp->dport != 5000) { if (udp->dport != 5000) {
goto EOP; goto EOP;
} }
......
...@@ -15,20 +15,26 @@ struct IPLeaf { ...@@ -15,20 +15,26 @@ struct IPLeaf {
BPF_TABLE("hash", struct IPKey, struct IPLeaf, stats, 256); BPF_TABLE("hash", struct IPKey, struct IPLeaf, stats, 256);
int on_packet(struct __sk_buff *skb) { int on_packet(struct __sk_buff *skb) {
BEGIN(ethernet); u8 *cursor = 0;
ethernet: {
PROTO(ethernet) { struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
switch (ethernet->type) { switch (ethernet->type) {
case 0x0800: goto ip; case ETH_P_IP: goto ip;
case 0x8100: goto dot1q; case ETH_P_8021Q: goto dot1q;
default: goto EOP;
} }
} }
PROTO(dot1q) {
dot1q: {
struct dot1q_t *dot1q = cursor_advance(cursor, sizeof(*dot1q));
switch (dot1q->type) { switch (dot1q->type) {
case 0x0800: goto ip; case ETH_P_8021Q: goto ip;
default: goto EOP;
} }
} }
PROTO(ip) {
ip: {
struct ip_t *ip = cursor_advance(cursor, sizeof(*ip));
int rx = 0, tx = 0; int rx = 0, tx = 0;
struct IPKey key; struct IPKey key;
if (ip->dst > ip->src) { if (ip->dst > ip->src) {
...@@ -45,6 +51,7 @@ int on_packet(struct __sk_buff *skb) { ...@@ -45,6 +51,7 @@ int on_packet(struct __sk_buff *skb) {
lock_xadd(&leaf->rx_pkts, rx); lock_xadd(&leaf->rx_pkts, rx);
lock_xadd(&leaf->tx_pkts, tx); lock_xadd(&leaf->tx_pkts, tx);
} }
EOP: EOP:
return 0; return 0;
} }
...@@ -14,29 +14,33 @@ struct IPLeaf { ...@@ -14,29 +14,33 @@ struct IPLeaf {
BPF_TABLE("hash", struct IPKey, struct IPLeaf, xlate, 1024); BPF_TABLE("hash", struct IPKey, struct IPLeaf, xlate, 1024);
int on_packet(struct __sk_buff *skb) { int on_packet(struct __sk_buff *skb) {
u8 *cursor = 0;
u32 orig_dip = 0; u32 orig_dip = 0;
u32 orig_sip = 0; u32 orig_sip = 0;
struct IPLeaf *xleaf; struct IPLeaf *xleaf;
BEGIN(ethernet); ethernet: {
PROTO(ethernet) { struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
switch (ethernet->type) { switch (ethernet->type) {
case 0x0800: goto ip; case ETH_P_IP: goto ip;
case 0x0806: goto arp; case ETH_P_ARP: goto arp;
case 0x8100: goto dot1q; case ETH_P_8021Q: goto dot1q;
default: goto EOP;
} }
goto EOP;
} }
PROTO(dot1q) { dot1q: {
struct dot1q_t *dot1q = cursor_advance(cursor, sizeof(*dot1q));
switch (dot1q->type) { switch (dot1q->type) {
case 0x0806: goto arp; case ETH_P_IP: goto ip;
case 0x0800: goto ip; case ETH_P_ARP: goto arp;
default: goto EOP;
} }
goto EOP;
} }
PROTO(arp) {
arp: {
struct arp_t *arp = cursor_advance(cursor, sizeof(*arp));
orig_dip = arp->tpa; orig_dip = arp->tpa;
orig_sip = arp->spa; orig_sip = arp->spa;
struct IPKey key = {.dip=orig_dip, .sip=orig_sip}; struct IPKey key = {.dip=orig_dip, .sip=orig_sip};
...@@ -49,7 +53,8 @@ int on_packet(struct __sk_buff *skb) { ...@@ -49,7 +53,8 @@ int on_packet(struct __sk_buff *skb) {
goto EOP; goto EOP;
} }
PROTO(ip) { ip: {
struct ip_t *ip = cursor_advance(cursor, sizeof(*ip));
orig_dip = ip->dst; orig_dip = ip->dst;
orig_sip = ip->src; orig_sip = ip->src;
struct IPKey key = {.dip=orig_dip, .sip=orig_sip}; struct IPKey key = {.dip=orig_dip, .sip=orig_sip};
...@@ -64,11 +69,12 @@ int on_packet(struct __sk_buff *skb) { ...@@ -64,11 +69,12 @@ int on_packet(struct __sk_buff *skb) {
switch (ip->nextp) { switch (ip->nextp) {
case 6: goto tcp; case 6: goto tcp;
case 17: goto udp; case 17: goto udp;
default: goto EOP;
} }
goto EOP;
} }
PROTO(udp) { udp: {
struct udp_t *udp = cursor_advance(cursor, sizeof(*udp));
if (xleaf) { if (xleaf) {
incr_cksum_l4(&udp->crc, orig_dip, xleaf->xdip, 1); incr_cksum_l4(&udp->crc, orig_dip, xleaf->xdip, 1);
incr_cksum_l4(&udp->crc, orig_sip, xleaf->xsip, 1); incr_cksum_l4(&udp->crc, orig_sip, xleaf->xsip, 1);
...@@ -76,7 +82,8 @@ int on_packet(struct __sk_buff *skb) { ...@@ -76,7 +82,8 @@ int on_packet(struct __sk_buff *skb) {
goto EOP; goto EOP;
} }
PROTO(tcp) { tcp: {
struct tcp_t *tcp = cursor_advance(cursor, sizeof(*tcp));
if (xleaf) { if (xleaf) {
incr_cksum_l4(&tcp->cksum, orig_dip, xleaf->xdip, 1); incr_cksum_l4(&tcp->cksum, orig_dip, xleaf->xdip, 1);
incr_cksum_l4(&tcp->cksum, orig_sip, xleaf->xsip, 1); incr_cksum_l4(&tcp->cksum, orig_sip, xleaf->xsip, 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment