summaryrefslogtreecommitdiff
path: root/src/ipcpd/shim-eth-llc
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-10-06 14:27:53 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-10-06 16:01:14 +0200
commit78d143e1487ef6212bda84702307c236021afcc7 (patch)
tree7f977513129b4a43eac102af4abe6457cb2632c9 /src/ipcpd/shim-eth-llc
parent170a60e4770a8fd12c50adfd6d3d34cd533ad570 (diff)
downloadouroboros-78d143e1487ef6212bda84702307c236021afcc7.tar.gz
ouroboros-78d143e1487ef6212bda84702307c236021afcc7.zip
ipcpd: Filter traffic on shim-eth-llc
Now correctly handles and drops non-ouroboros traffic.
Diffstat (limited to 'src/ipcpd/shim-eth-llc')
-rw-r--r--src/ipcpd/shim-eth-llc/main.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c
index 03e8beb1..c5e6d74d 100644
--- a/src/ipcpd/shim-eth-llc/main.c
+++ b/src/ipcpd/shim-eth-llc/main.c
@@ -520,9 +520,9 @@ static void * eth_llc_ipcp_sdu_reader(void * o)
#else
if (memcmp(eth_llc_data.device.sll_addr,
#endif
- &llc_frame->dst_hwaddr,
+ llc_frame->dst_hwaddr,
MAC_SIZE) &&
- memcmp(br_addr, &llc_frame->dst_hwaddr, MAC_SIZE)) {
+ memcmp(br_addr, llc_frame->dst_hwaddr, MAC_SIZE)) {
#if defined(PACKET_RX_RING) && defined(PACKET_TX_RING)
offset = (offset + 1) & (SHM_BUFFER_SIZE - 1);
header->tp_status = TP_STATUS_KERNEL;
@@ -530,12 +530,22 @@ static void * eth_llc_ipcp_sdu_reader(void * o)
continue;
}
+ memcpy(&length, &llc_frame->length, sizeof(length));
+ length = ntohs(length);
+
+ if (length > 0x05FF) { /* DIX */
+#if defined(PACKET_RX_RING) && defined(PACKET_TX_RING)
+ offset = (offset + 1) & (SHM_BUFFER_SIZE -1);
+ header->tp_status = TP_STATUS_KERNEL;
+#endif
+ continue;
+ }
+
+ length -= LLC_HEADER_SIZE;
+
dsap = reverse_bits(llc_frame->dsap);
ssap = reverse_bits(llc_frame->ssap);
- memcpy(&length, &llc_frame->length, sizeof(length));
- length = ntohs(length) - LLC_HEADER_SIZE;
-
if (ssap == MGMT_SAP && dsap == MGMT_SAP) {
eth_llc_ipcp_mgmt_frame(&llc_frame->payload,
length,
@@ -553,9 +563,21 @@ static void * eth_llc_ipcp_sdu_reader(void * o)
continue;
}
+ if (eth_llc_data.fd_to_ef[fd].r_sap != ssap
+ || memcmp(eth_llc_data.fd_to_ef[fd].r_addr,
+ llc_frame->src_hwaddr, MAC_SIZE)) {
+ pthread_rwlock_unlock(&eth_llc_data.flows_lock);
+#if defined(PACKET_RX_RING) && defined(PACKET_TX_RING)
+ offset = (offset + 1) & (SHM_BUFFER_SIZE -1);
+ header->tp_status = TP_STATUS_KERNEL;
+#endif
+ continue;
+ }
+
pthread_rwlock_unlock(&eth_llc_data.flows_lock);
flow_write(fd, &llc_frame->payload, length);
+
}
#if defined(PACKET_RX_RING) && defined(PACKET_TX_RING)
offset = (offset + 1) & (SHM_BUFFER_SIZE -1);
@@ -705,7 +727,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
device.sdl_alen = MAC_SIZE;
/* TODO: replace socket calls with bpf for BSD */
LOG_MISSING;
- fd = socket(AF_LINK, SOCK_RAW, 0);
+ skfd = socket(AF_LINK, SOCK_RAW, 0);
#else
device.sll_ifindex = idx;
device.sll_family = AF_PACKET;