mirror of
https://github.com/ntop/n2n.git
synced 2024-09-20 00:51:10 +02:00
make edge restore original metric value (-x) at program's end (#742)
This commit is contained in:
parent
e09f3a4875
commit
6a831879d3
|
@ -21,14 +21,19 @@
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#endif /* #if defined(__MINGW32__) */
|
#endif /* #if defined(__MINGW32__) */
|
||||||
|
|
||||||
|
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <winioctl.h>
|
#include <ws2def.h>
|
||||||
#include <iptypes.h>
|
#include <ws2ipdef.h>
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#include <Iphlpapi.h>
|
#include <Iphlpapi.h>
|
||||||
#pragma comment(lib,"Iphlpapi.lib")
|
#pragma comment(lib,"Iphlpapi.lib")
|
||||||
#endif
|
#endif
|
||||||
|
#include <netioapi.h>
|
||||||
|
#include <winioctl.h>
|
||||||
|
#include <iptypes.h>
|
||||||
|
|
||||||
|
|
||||||
#include "wintap.h"
|
#include "wintap.h"
|
||||||
|
|
||||||
|
@ -81,6 +86,7 @@ typedef struct tuntap_dev {
|
||||||
uint32_t device_mask;
|
uint32_t device_mask;
|
||||||
unsigned int mtu;
|
unsigned int mtu;
|
||||||
unsigned int metric;
|
unsigned int metric;
|
||||||
|
unsigned int metric_original;
|
||||||
} tuntap_dev;
|
} tuntap_dev;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -339,16 +339,27 @@ int open_wintap(struct tuntap_dev *device,
|
||||||
|
|
||||||
/* metric */
|
/* metric */
|
||||||
|
|
||||||
|
PMIB_IPINTERFACE_ROW Row;
|
||||||
|
|
||||||
if(metric) { /* try to change only if a value has been given, otherwise leave with default or as set before */
|
if(metric) { /* try to change only if a value has been given, otherwise leave with default or as set before */
|
||||||
|
// find & store original metric
|
||||||
|
Row = calloc(1, sizeof(MIB_IPINTERFACE_ROW));
|
||||||
|
InitializeIpInterfaceEntry(Row);
|
||||||
|
Row->InterfaceIndex = device->if_idx;
|
||||||
|
Row->Family = AF_INET;
|
||||||
|
GetIpInterfaceEntry(Row);
|
||||||
|
|
||||||
|
device->metric_original = Row->Metric;
|
||||||
device->metric = metric;
|
device->metric = metric;
|
||||||
|
|
||||||
_snprintf(cmd, sizeof(cmd),
|
// set new value
|
||||||
"netsh interface ipv4 set interface \"%s\" metric=%d > nul",
|
Row->Metric = metric;
|
||||||
device->ifName, device->metric);
|
|
||||||
|
|
||||||
if(system(cmd) != 0)
|
// store
|
||||||
printf("WARNING: Unable to set device %s parameters metric=%d [%s]\n",
|
Row->SitePrefixLength = 0; /* if not set to zero, following function call fails... */
|
||||||
device->ifName, device->metric, cmd);
|
SetIpInterfaceEntry(Row);
|
||||||
|
|
||||||
|
free(Row);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ****************** */
|
/* ****************** */
|
||||||
|
@ -443,6 +454,27 @@ int tuntap_open(struct tuntap_dev *device,
|
||||||
/* ************************************************ */
|
/* ************************************************ */
|
||||||
|
|
||||||
void tuntap_close(struct tuntap_dev *tuntap) {
|
void tuntap_close(struct tuntap_dev *tuntap) {
|
||||||
|
|
||||||
|
PMIB_IPINTERFACE_ROW Row;
|
||||||
|
|
||||||
|
if(tuntap->metric) { /* only required if a value has been given (and thus stored) */
|
||||||
|
// find device entry
|
||||||
|
Row = calloc(1, sizeof(MIB_IPINTERFACE_ROW));
|
||||||
|
InitializeIpInterfaceEntry(Row);
|
||||||
|
Row->InterfaceIndex = tuntap->if_idx;
|
||||||
|
Row->Family = AF_INET;
|
||||||
|
GetIpInterfaceEntry(Row);
|
||||||
|
|
||||||
|
// restore original value
|
||||||
|
Row->Metric = tuntap->metric_original;
|
||||||
|
|
||||||
|
// store
|
||||||
|
Row->SitePrefixLength = 0; /* if not set to zero, following function call fails... */
|
||||||
|
SetIpInterfaceEntry(Row);
|
||||||
|
|
||||||
|
free(Row);
|
||||||
|
}
|
||||||
|
|
||||||
CloseHandle(tuntap->device_handle);
|
CloseHandle(tuntap->device_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user