Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Revert "Removed setting of MTU with ioctl() since ICMP message too bi…

…g errors can be sent."

This reverts commit 83c2a8c.
  • Loading branch information...
commit 87187ecbe20c55686635992b69f87555bfc0c1cd 1 parent 6fb67a2
Caleb James DeLisle authored
27 admin/angel/Core.c
View
@@ -64,6 +64,32 @@
// Failsafe: abort if more than 2^22 bytes are allocated (4MB)
#define ALLOCATOR_FAILSAFE (1<<22)
+/**
+ * The worst possible packet overhead.
+ * assuming the packet needs to be handed off to another node
+ * because we have no route to the destination.
+ * and the CryptoAuths to both the destination and the handoff node are both timed out.
+ */
+#define WORST_CASE_OVERHEAD ( \
+ /* TODO: Headers_IPv4_SIZE */ 20 \
+ + Headers_UDPHeader_SIZE \
+ + 4 /* Nonce */ \
+ + 16 /* Poly1305 authenticator */ \
+ + Headers_SwitchHeader_SIZE \
+ + Headers_CryptoAuth_SIZE \
+ + Headers_IP6Header_SIZE \
+ + Headers_CryptoAuth_SIZE \
+)
+
+/** The default MTU, assuming the external MTU is 1492 (common for PPPoE DSL) */
+#define DEFAULT_MTU ( \
+ 1492 \
+ - WORST_CASE_OVERHEAD \
+ + Headers_IP6Header_SIZE /* The OS subtracts the IP6 header. */ \
+ + Headers_CryptoAuth_SIZE /* Linux won't let set the MTU below 1280.
+ TODO: make sure we never hand off to a node for which the CA session is expired. */ \
+)
+
static void parsePrivateKey(uint8_t privateKey[32],
struct Address* addr,
struct Except* eh)
@@ -141,6 +167,7 @@ void Core_initTunnel(String* desiredDeviceName,
Ducttape_setUserInterface(dt, &icmp->internal);
TUNConfigurator_setIpAddress(assignedTunName, ipAddr, addressPrefix, logger, eh);
+ TUNConfigurator_setMTU(assignedTunName, DEFAULT_MTU, logger, eh);
}
/*
18 interface/TUNConfigurator.h
View
@@ -74,4 +74,22 @@ void TUNConfigurator_setIpAddress(const char* interfaceName,
int prefixLen,
struct Log* logger,
struct Except* eh);
+
+/**
+ * Set the MTU of an interface.
+ *
+ * @param interfaceName the name of the interface to set the MTU for.
+ * @param mtu the desired MTU.
+ * @param logger where to write information.
+ * @param eh if this function fails, it will raise one of the following.
+ * TUNConfigurator_setMTU_INTERNAL Catch all exception code for failures.
+ * TUNConfigurator_ERROR_GETTING_ADMIN_SOCKET Error getting admin socket for interface.
+ * TUNConfigurator_ERROR_ENABLING_INTERFACE If the interface cannot be brought up.
+ */
+#define TUNConfigurator_setMTU_INTERNAL -1
+void TUNConfigurator_setMTU(const char* interfaceName,
+ uint32_t mtu,
+ struct Log* logger,
+ struct Except* eh);
+
#endif
32 interface/TUNConfigurator_FreeBSD.c
View
@@ -177,3 +177,35 @@ void TUNConfigurator_setIpAddress(const char* interfaceName,
close(s);
}
+
+void TUNConfigurator_setMTU(const char* interfaceName,
+ uint32_t mtu,
+ struct Log* logger,
+ struct Except* eh)
+{
+ int s = socket(AF_INET6, SOCK_DGRAM, 0);
+
+ if (s < 0) {
+ Except_raise(eh,
+ TUNConfigurator_ERROR_GETTING_ADMIN_SOCKET,
+ "socket() failed [%s]",
+ Errno_getString());
+ }
+
+
+ struct ifreq ifRequest;
+
+ strncpy(ifRequest.ifr_name, interfaceName, IFNAMSIZ);
+ ifRequest.ifr_mtu = mtu;
+
+ Log_info(logger, "Setting MTU for device [%s] to [%u] bytes.", interfaceName, mtu);
+
+ if (ioctl(s, SIOCSIFMTU, &ifRequest) < 0) {
+ enum Errno err = Errno_get();
+ close(s);
+ Except_raise(eh,
+ TUNConfigurator_setMTU_INTERNAL,
+ "ioctl(SIOCSIFMTU) failed [%s]",
+ Errno_strerror(err));
+ }
+}
8 interface/TUNConfigurator_Illumos.c
View
@@ -246,3 +246,11 @@ void* TUNConfigurator_initTun(const char* interfaceName,
intptr_t ret = (intptr_t) tunFd;
return (void*) ret;
}
+
+void TUNConfigurator_setMTU(const char* interfaceName,
+ uint32_t mtu,
+ struct Log* logger,
+ struct Except* eh)
+{
+ Except_raise(eh, TUNConfigurator_setMTU_INTERNAL, "Not implemented in IlLumos");
+}
19 interface/TUNConfigurator_Linux.c
View
@@ -187,3 +187,22 @@ void TUNConfigurator_setIpAddress(const char* interfaceName,
"ioctl(SIOCSIFADDR) failed: [%s]", Errno_strerror(err));
}
}
+
+void TUNConfigurator_setMTU(const char* interfaceName,
+ uint32_t mtu,
+ struct Log* logger,
+ struct Except* eh)
+{
+ struct ifreq ifRequest;
+ int s = socketForIfName(interfaceName, eh, &ifRequest);
+
+ Log_info(logger, "Setting MTU for device [%s] to [%u] bytes.", interfaceName, mtu);
+
+ ifRequest.ifr_mtu = mtu;
+ if (ioctl(s, SIOCSIFMTU, &ifRequest) < 0) {
+ enum Errno err = Errno_get();
+ close(s);
+ Except_raise(eh, TUNConfigurator_setMTU_INTERNAL,
+ "ioctl(SIOCSIFMTU) failed: [%s]", Errno_strerror(err));
+ }
+}
32 interface/TUNConfigurator_OSX.c
View
@@ -203,3 +203,35 @@ void TUNConfigurator_setIpAddress(const char* interfaceName,
close(s);
}
+
+void TUNConfigurator_setMTU(const char* interfaceName,
+ uint32_t mtu,
+ struct Log* logger,
+ struct Except* eh)
+{
+ int s = socket(AF_INET6, SOCK_DGRAM, 0);
+
+ if (s < 0) {
+ Except_raise(eh,
+ TUNConfigurator_ERROR_GETTING_ADMIN_SOCKET,
+ "socket() failed [%s]",
+ Errno_getString());
+ }
+
+
+ struct ifreq ifRequest;
+
+ strncpy(ifRequest.ifr_name, interfaceName, IFNAMSIZ);
+ ifRequest.ifr_mtu = mtu;
+
+ Log_info(logger, "Setting MTU for device [%s] to [%u] bytes.", interfaceName, mtu);
+
+ if (ioctl(s, SIOCSIFMTU, &ifRequest) < 0) {
+ enum Errno err = Errno_get();
+ close(s);
+ Except_raise(eh,
+ TUNConfigurator_setMTU_INTERNAL,
+ "ioctl(SIOCSIFMTU) failed [%s]",
+ Errno_strerror(err));
+ }
+}
32 interface/TUNConfigurator_OpenBSD.c
View
@@ -170,3 +170,35 @@ void TUNConfigurator_setIpAddress(const char* interfaceName,
close(s);
}
+
+void TUNConfigurator_setMTU(const char* interfaceName,
+ uint32_t mtu,
+ struct Log* logger,
+ struct Except* eh)
+{
+ int s = socket(AF_INET6, SOCK_DGRAM, 0);
+
+ if (s < 0) {
+ Except_raise(eh,
+ TUNConfigurator_ERROR_GETTING_ADMIN_SOCKET,
+ "socket() failed [%s]",
+ Errno_getString());
+ }
+
+
+ struct ifreq ifRequest;
+
+ strncpy(ifRequest.ifr_name, interfaceName, IFNAMSIZ);
+ ifRequest.ifr_mtu = mtu;
+
+ Log_info(logger, "Setting MTU for device [%s] to [%u] bytes.", interfaceName, mtu);
+
+ if (ioctl(s, SIOCSIFMTU, &ifRequest) < 0) {
+ enum Errno err = Errno_get();
+ close(s);
+ Except_raise(eh,
+ TUNConfigurator_setMTU_INTERNAL,
+ "ioctl(SIOCSIFMTU) failed [%s]",
+ Errno_strerror(err));
+ }
+}
7 interface/TUNConfigurator_W32.c
View
@@ -30,3 +30,10 @@ void TUNConfigurator_setIpAddress(const char* interfaceName,
struct Except* eh)
{
}
+
+void TUNConfigurator_setMTU(const char* interfaceName,
+ uint32_t mtu,
+ struct Log* logger,
+ struct Except* eh)
+{
+}
Please sign in to comment.
Something went wrong with that request. Please try again.