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: Brenden Blanco <bblanco@plumgrid.com>
diff --git a/examples/tc_neighbor_sharing.c b/examples/tc_neighbor_sharing.c
index 87ea0ea..8d1c3bf 100644
--- a/examples/tc_neighbor_sharing.c
+++ b/examples/tc_neighbor_sharing.c
@@ -19,14 +19,16 @@
// returns: > 0 when an IP is known
// = 0 when an IP is not known, or non-IP traffic
int classify_wan(struct __sk_buff *skb) {
- BEGIN(ethernet);
- PROTO(ethernet) {
+ u8 *cursor = 0;
+ ethernet: {
+ struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
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;
struct ipkey key = {.client_ip=dip};
int *val = learned_ips.lookup(&key);
@@ -42,14 +44,16 @@
// Mark the inserted entry with a non-zero value to be used by the classify_wan
// lookup.
int classify_neighbor(struct __sk_buff *skb) {
- BEGIN(ethernet);
- PROTO(ethernet) {
+ u8 *cursor = 0;
+ ethernet: {
+ struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
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;
struct ipkey key = {.client_ip=sip};
int val = 1;