Last active
December 20, 2015 03:59
-
-
Save piotrjurkiewicz/6067858 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ./src/tap-bridge/model/tap-bridge.cc 2013-05-12 18:50:16.000000000 +0200 | |
+++ ./src/tap-bridge/model/tap-bridge.cc 2013-07-17 05:44:32.363514463 +0200 | |
@@ -44,6 +44,13 @@ | |
#include <cstdlib> | |
#include <unistd.h> | |
+#include <stdio.h> | |
+#include <fcntl.h> | |
+#include <net/if.h> | |
+#include <linux/if_tun.h> | |
+#include <sys/ioctl.h> | |
+ | |
+ | |
// | |
// Sometimes having a tap-creator is actually more trouble than solution. In | |
// these cases you can uncomment the define of TAP_CREATOR below and the | |
@@ -55,12 +62,6 @@ | |
// #define NO_CREATOR | |
-#ifdef NO_CREATOR | |
-#include <fcntl.h> | |
-#include <net/if.h> | |
-#include <linux/if_tun.h> | |
-#include <sys/ioctl.h> | |
-#endif | |
NS_LOG_COMPONENT_DEFINE ("TapBridge"); | |
@@ -630,15 +631,50 @@ TapBridge::CreateTap (void) | |
int *rawSocket = (int*)CMSG_DATA (cmsg); | |
NS_LOG_INFO ("Got the socket from the socket creator = " << *rawSocket); | |
m_sock = *rawSocket; | |
- return; | |
} | |
else | |
{ | |
NS_LOG_INFO ("Got SCM_RIGHTS, but with bad magic " << magic); | |
} | |
} | |
+ else | |
+ { | |
+ NS_FATAL_ERROR ("Did not get the raw socket from the socket creator"); | |
+ } | |
+ } | |
+ if (m_mode == USE_LOCAL || m_mode == USE_BRIDGE) | |
+ { | |
+ // | |
+ // Set the ns-3 device's mac address to the overlying container's | |
+ // mac address | |
+ // | |
+ struct ifreq s; | |
+ int fd; | |
+ int ioctl_result; | |
+ | |
+ fd = socket (PF_INET, SOCK_DGRAM, 0); | |
+ strcpy (s.ifr_name, m_tapDeviceName.c_str()); | |
+ | |
+ NS_LOG_INFO ("Trying to get MacAddr of " << m_tapDeviceName); | |
+ ioctl_result = ioctl (fd, SIOCGIFHWADDR, &s); | |
+ | |
+ if (ioctl_result == 0) | |
+ { | |
+ unsigned char *mac = (unsigned char *)s.ifr_hwaddr.sa_data; | |
+ char hexmac[18]; | |
+ sprintf(hexmac, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x" , mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); | |
+ Mac48Address learnedMac = Mac48Address ((const char *)hexmac); | |
+ NS_LOG_INFO ("Learned Tap device MacAddr is " << learnedMac << ": setting ns-3 device to use this address"); | |
+ m_bridgedDevice->SetAddress (Mac48Address::ConvertFrom (learnedMac)); | |
+ m_ns3AddressRewritten = true; | |
+ } | |
+ else | |
+ { | |
+ NS_LOG_INFO ("Cannot get MacAddr of Tap device: " << m_tapDeviceName << " while in USE_LOCAL/USE_BRIDGE mode"); | |
+ NS_LOG_INFO ("Underlying ns-3 device will continue to use default address, what can lead to connectivity errors"); | |
+ } | |
} | |
- NS_FATAL_ERROR ("Did not get the raw socket from the socket creator"); | |
+ return; | |
} | |
} | |
@@ -731,17 +767,6 @@ TapBridge::ForwardToBridgedDevice (uint8 | |
// | |
NS_ASSERT_MSG (Mac48Address::ConvertFrom (src) != Mac48Address ("ff:ff:ff:ff:ff:ff"), | |
"TapBridge::ForwardToBridgedDevice: Source addr is broadcast"); | |
- if (m_ns3AddressRewritten == false) | |
- { | |
- // | |
- // Set the ns-3 device's mac address to the overlying container's | |
- // mac address | |
- // | |
- Mac48Address learnedMac = Mac48Address::ConvertFrom (src); | |
- NS_LOG_LOGIC ("Learned MacAddr is " << learnedMac << ": setting ns-3 device to use this address"); | |
- m_bridgedDevice->SetAddress (Mac48Address::ConvertFrom (learnedMac)); | |
- m_ns3AddressRewritten = true; | |
- } | |
// | |
// If we are operating in USE_LOCAL mode, we may be attached to an ns-3 | |
// device that does not support bridging (SupportsSendFrom returns false). | |
--- ./src/tap-bridge/model/tap-bridge.h 2013-05-12 18:50:16.000000000 +0200 | |
+++ ./src/tap-bridge/model/tap-bridge.h 2013-07-17 05:39:34.007507071 +0200 | |
@@ -448,7 +448,7 @@ private: | |
* \internal | |
* | |
* Whether the MAC address of the underlying ns-3 device has already been | |
- * rewritten is stored in this variable (for UseLocal mode only). | |
+ * rewritten is stored in this variable (for UseLocal/UseBridge mode only). | |
*/ | |
bool m_ns3AddressRewritten; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment