diff options
author | Sander Vrijders <[email protected]> | 2016-06-14 17:56:45 +0200 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2016-06-14 18:00:36 +0200 |
commit | 6cc20e6d98aec8d1da0740a2a890e984e634445a (patch) | |
tree | b6cdd28d260cf8f838c3299455ab1070a6e4c25c | |
parent | af2ab9b56fb4b541abd067c9a6e2b3f62a4c4aab (diff) | |
download | ouroboros-6cc20e6d98aec8d1da0740a2a890e984e634445a.tar.gz ouroboros-6cc20e6d98aec8d1da0740a2a890e984e634445a.zip |
ipcpd: Fix wrong length in shim-eth-llc
The shim Ethernet with LLC was using the frame length in the header of
the 802.3 frame, which contained a wrong value when sent over the
wire. Probably the kernel filled in a wrong value. Now it uses the
length as reported by recv.
-rw-r--r-- | src/ipcpd/shim-eth-llc/main.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c index fe7b5dcb..1ff3496b 100644 --- a/src/ipcpd/shim-eth-llc/main.c +++ b/src/ipcpd/shim-eth-llc/main.c @@ -65,6 +65,7 @@ typedef ShimEthLlcMsg shim_eth_llc_msg_t; #define MGMT_SAP 0x01 #define SHIM_ETH_LLC_MAX_SDU_SIZE 1500 #define MAC_SIZE 6 +#define LLC_HEADER_SIZE 3 #define MAX_SAPS 64 /* global for trapping signal */ @@ -278,7 +279,7 @@ static int eth_llc_ipcp_send_frame(uint8_t dst_addr[MAC_SIZE], return -1; } - length = htons(len); + length = htons(len + LLC_HEADER_SIZE); memcpy(frame, dst_addr, MAC_SIZE * sizeof(uint8_t)); frame_len += MAC_SIZE; @@ -580,8 +581,9 @@ static void * eth_llc_ipcp_sdu_reader(void * o) rw_lock_unlock(&_ipcp->state_lock); - if (recv(shim_data(_ipcp)->s_fd, buf, - SHIM_ETH_LLC_MAX_SDU_SIZE, 0) < 0) { + frame_len = recv(shim_data(_ipcp)->s_fd, buf, + SHIM_ETH_LLC_MAX_SDU_SIZE, 0); + if (frame_len < 0) { LOG_ERR("Failed to recv frame."); continue; } @@ -600,13 +602,14 @@ static void * eth_llc_ipcp_sdu_reader(void * o) for (; i < 2 * MAC_SIZE; i++) src_mac[i - MAC_SIZE] = buf[i]; - frame_len = ((buf[i]) << 8) + buf[i + 1]; i += 2; dsap = reverse_bits(buf[i++]); ssap = reverse_bits(buf[i++]); i++; + frame_len -= i; + if (ssap == MGMT_SAP && dsap == MGMT_SAP) { eth_llc_ipcp_mgmt_frame((uint8_t *) (buf + i), |