Commit 77b26e1a authored by 4ast's avatar 4ast

Merge pull request #44 from iovisor/yhs_dev

use ethernet->src/dst to get mac address instead of primitive load_* …
parents febb97e1 5c483e30
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
// Licensed under the Apache License, Version 2.0 (the "License") // Licensed under the Apache License, Version 2.0 (the "License")
#include <bcc/proto.h> #include <bcc/proto.h>
/* compiler workaround */ #define _memcpy __builtin_memcpy
#define _htonl __builtin_bswap32
#define _htons __builtin_bswap16
// meta data passed between bpf programs // meta data passed between bpf programs
typedef struct bpf_metadata { typedef struct bpf_metadata {
...@@ -117,6 +115,7 @@ static int br_common(struct __sk_buff *skb, int which_br) { ...@@ -117,6 +115,7 @@ static int br_common(struct __sk_buff *skb, int which_br) {
u32 tx_port_id; u32 tx_port_id;
bpf_dest_t *dest_p; bpf_dest_t *dest_p;
u32 index, *rtrif_p; u32 index, *rtrif_p;
u64 mac_addr;
if (skb->tc_index == 0) { if (skb->tc_index == 0) {
skb->tc_index = 1; skb->tc_index = 1;
...@@ -129,9 +128,8 @@ static int br_common(struct __sk_buff *skb, int which_br) { ...@@ -129,9 +128,8 @@ static int br_common(struct __sk_buff *skb, int which_br) {
BEGIN(ethernet); BEGIN(ethernet);
PROTO(ethernet) { PROTO(ethernet) {
// ethernet->dst seems not working, so tentatively use the primitive C API. mac_addr = bpf_htonll(ethernet->dst);
*(__u32 *)&dmac.addr[0] = _htonl(load_word(skb, 0)); _memcpy(dmac.addr, (u8 *)&mac_addr + 2, 6);
*(__u16 *)&dmac.addr[4] = _htons(load_half(skb, 4));
if (meta.prog_id != 0) { if (meta.prog_id != 0) {
/* send to the router */ /* send to the router */
if (dmac.addr[0] & dmac.addr[1] & dmac.addr[2] & dmac.addr[3] & dmac.addr[4] & dmac.addr[5] == 0xff) { if (dmac.addr[0] & dmac.addr[1] & dmac.addr[2] & dmac.addr[3] & dmac.addr[4] & dmac.addr[5] == 0xff) {
...@@ -172,7 +170,6 @@ static int br_common(struct __sk_buff *skb, int which_br) { ...@@ -172,7 +170,6 @@ static int br_common(struct __sk_buff *skb, int which_br) {
PROTO(arp) { PROTO(arp) {
/* mac learning */ /* mac learning */
// arpop = load_half(skb, 20);
arpop = arp->oper; arpop = arp->oper;
if (arpop == 2) { if (arpop == 2) {
index = 0; index = 0;
...@@ -184,9 +181,8 @@ static int br_common(struct __sk_buff *skb, int which_br) { ...@@ -184,9 +181,8 @@ 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;
*(__u16 *)&smac.addr[0] = _htons(load_half(skb, 6)); mac_addr = bpf_htonll(ethernet->src);
*(__u16 *)&smac.addr[2] = _htons(load_half(skb, 8)); _memcpy(smac.addr, (u8 *)&mac_addr + 2, 6);
*(__u16 *)&smac.addr[4] = _htons(load_half(skb, 10));
if (which_br == 1) if (which_br == 1)
br1_mac_ifindex.update(&smac, &ifindex); br1_mac_ifindex.update(&smac, &ifindex);
else else
......
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