Commit 3a55d749 authored by Jondy Zhao's avatar Jondy Zhao

Add target testc.exe in the Makefile, which is used to

verify the functions in the cyginet.c
Remove "nexthop" from "netsh" commoand if ipv6 gate is empty.
Add function cyginet_ipv4_index2ifname
parent 07b5479c
...@@ -6,7 +6,7 @@ DEFINES = $(PLATFORM_DEFINES) ...@@ -6,7 +6,7 @@ DEFINES = $(PLATFORM_DEFINES)
CFLAGS = $(CDEBUGFLAGS) $(DEFINES) $(EXTRA_DEFINES) CFLAGS = $(CDEBUGFLAGS) $(DEFINES) $(EXTRA_DEFINES)
LDLIBS = -lrt -liphlpapi -lws2_32 -lwlanapi -lole32 -lsetupapi LDLIBS = -lrt
SRCS = babeld.c net.c kernel.c util.c interface.c source.c neighbour.c \ SRCS = babeld.c net.c kernel.c util.c interface.c source.c neighbour.c \
route.c xroute.c message.c resend.c configuration.c local.c route.c xroute.c message.c resend.c configuration.c local.c
...@@ -20,14 +20,15 @@ ifneq "$(WINVER)" "" ...@@ -20,14 +20,15 @@ ifneq "$(WINVER)" ""
SRCS += cyginet.c SRCS += cyginet.c
OBJS += cyginet.o OBJS += cyginet.o
LDLIBS += -liphlpapi -lws2_32 -lwlanapi -lole32 -lsetupapi
KERNEL_SOUCES += kernel_cygwin.c KERNEL_SOUCES += kernel_cygwin.c
ifeq "$(WINVER)" "XP" ifeq "$(WINVER)" "XP"
DEFINES += -D_WIN32_WINNT=0x0503 CFLAGS += -D_WIN32_WINNT=0x0503
endif endif
ifeq "$(WINVER)" "VISTA" ifeq "$(WINVER)" "VISTA"
DEFINES += -D_WIN32_WINNT=0x0600 CLFAGS += -D_WIN32_WINNT=0x0600
endif endif
endif endif
...@@ -67,3 +68,8 @@ clean: ...@@ -67,3 +68,8 @@ clean:
-rm -f babeld babeld.html *.o *~ core TAGS gmon.out -rm -f babeld babeld.html *.o *~ core TAGS gmon.out
kernel.o: $(KERNEL_SOURCES) kernel.o: $(KERNEL_SOURCES)
# Usage: ./testc.exe
# Verify most of the functions in the cyginet.c
testc.exe: cyginet.c
$(CC) $(CFLAGS) $(LDFLAGS) -DTEST_CYGINET -o $@ $< $(LDLIBS)
...@@ -31,6 +31,13 @@ Later Windows Vista, ...@@ -31,6 +31,13 @@ Later Windows Vista,
$ WINVER=VISTA make $ WINVER=VISTA make
It will generate babeld.exe in the current directory.
Build testc.exe, it's used to verify the functions in the cyginet.c
$ WINVER=XP make testc.exe
$ ./testc.exe
Interface Names Interface Names
=============== ===============
......
...@@ -44,10 +44,11 @@ ...@@ -44,10 +44,11 @@
#if defined (TEST_CYGINET) #if defined (TEST_CYGINET)
#define kdebugf printf #define kdebugf printf
#else #else
extern int debug;
void do_debugf(int level, const char *format, ...); void do_debugf(int level, const char *format, ...);
#define kdebugf(_args...) \ #define kdebugf(_args...) \
do { \ do { \
do_debugf(3, _args); \ if(!!(debug >= 3)) do_debugf(3, _args); \
} while(0) } while(0)
#endif #endif
...@@ -319,6 +320,7 @@ static int ...@@ -319,6 +320,7 @@ static int
libwinet_run_command(const char *command) libwinet_run_command(const char *command)
{ {
FILE *output; FILE *output;
printf("libwinet_run_command: %s\n", command);
kdebugf("libwinet_run_command: %s\n", command); kdebugf("libwinet_run_command: %s\n", command);
output = popen (command, "r"); output = popen (command, "r");
if (!output) if (!output)
...@@ -739,7 +741,7 @@ libwinet_edit_route_entry(const struct sockaddr *dest, ...@@ -739,7 +741,7 @@ libwinet_edit_route_entry(const struct sockaddr *dest,
const int MAX_BUFFER_SIZE = 1024; const int MAX_BUFFER_SIZE = 1024;
const char * cmdformat = "netsh interface ipv6 %s route " const char * cmdformat = "netsh interface ipv6 %s route "
"prefix=%s/%d interface=%d " "prefix=%s/%d interface=%d "
"nexthop=%s %s%d"; "%s%s %s%d";
char cmdbuf[MAX_BUFFER_SIZE]; char cmdbuf[MAX_BUFFER_SIZE];
char sdest[INET6_ADDRSTRLEN]; char sdest[INET6_ADDRSTRLEN];
char sgate[INET6_ADDRSTRLEN]; char sgate[INET6_ADDRSTRLEN];
...@@ -765,7 +767,8 @@ libwinet_edit_route_entry(const struct sockaddr *dest, ...@@ -765,7 +767,8 @@ libwinet_edit_route_entry(const struct sockaddr *dest,
sdest, sdest,
plen, plen,
ifindex, ifindex,
sgate, strcmp(sgate, "::") == 0 ? "" : "nexthop=",
strcmp(sgate, "::") == 0 ? "" : sgate,
cmdflag == RTM_DELETE ? "#" : "metric=", cmdflag == RTM_DELETE ? "#" : "metric=",
metric metric
) >= MAX_BUFFER_SIZE) ) >= MAX_BUFFER_SIZE)
...@@ -949,62 +952,6 @@ libwinet_set_registry_key(char *key, char * name, int value, int defvalue) ...@@ -949,62 +952,6 @@ libwinet_set_registry_key(char *key, char * name, int value, int defvalue)
return old; return old;
} }
static int
libwinet_get_loopback_index(int family)
{
IP_ADAPTER_ADDRESSES *pAdaptAddr = NULL;
IP_ADAPTER_ADDRESSES *pTmpAdaptAddr = NULL;
DWORD dwRet = 0;
DWORD dwSize = 0x10000;
DWORD dwReturn = 0;
dwRet = GetAdaptersAddresses(family,
GAA_FLAG_SKIP_ANYCAST \
| GAA_FLAG_SKIP_MULTICAST \
| GAA_FLAG_SKIP_DNS_SERVER \
| GAA_FLAG_SKIP_FRIENDLY_NAME,
NULL,
pAdaptAddr,
&dwSize
);
if (ERROR_BUFFER_OVERFLOW == dwRet) {
FREE(pAdaptAddr);
if (NULL == (pAdaptAddr = (IP_ADAPTER_ADDRESSES*)MALLOC(dwSize)))
return 0;
dwRet = GetAdaptersAddresses(family,
GAA_FLAG_SKIP_ANYCAST \
| GAA_FLAG_SKIP_MULTICAST \
| GAA_FLAG_SKIP_DNS_SERVER \
| GAA_FLAG_SKIP_FRIENDLY_NAME,
NULL,
pAdaptAddr,
&dwSize
);
}
if (NO_ERROR == dwRet) {
pTmpAdaptAddr = pAdaptAddr;
while (pTmpAdaptAddr) {
if (IF_TYPE_SOFTWARE_LOOPBACK == pTmpAdaptAddr -> IfType) {
dwReturn = family == AF_INET ?
pTmpAdaptAddr -> IfIndex :
pTmpAdaptAddr -> Ipv6IfIndex;
/* Loopback interface doesn't support both of Ipv4 or Ipv6 */
if (dwReturn)
break;
}
pTmpAdaptAddr = pTmpAdaptAddr->Next;
}
FREE(pAdaptAddr);
}
return dwReturn;
}
int int
cyginet_set_ipv6_forwards(int value) cyginet_set_ipv6_forwards(int value)
{ {
...@@ -1272,6 +1219,58 @@ cyginet_loopback_index(int family) ...@@ -1272,6 +1219,58 @@ cyginet_loopback_index(int family)
return 1; return 1;
} }
char *
cyginet_ipv4_index2ifname(int ifindex)
{
IP_ADAPTER_ADDRESSES *pAdaptAddr = NULL;
IP_ADAPTER_ADDRESSES *pTmpAdaptAddr = NULL;
DWORD dwRet = 0;
DWORD dwSize = 0x10000;
DWORD dwFamily = AF_INET;
char * ifname = NULL;
dwRet = GetAdaptersAddresses(dwFamily,
GAA_FLAG_SKIP_UNICAST \
| GAA_FLAG_SKIP_ANYCAST \
| GAA_FLAG_SKIP_MULTICAST \
| GAA_FLAG_SKIP_DNS_SERVER,
NULL,
pAdaptAddr,
&dwSize
);
if (ERROR_BUFFER_OVERFLOW == dwRet) {
FREE(pAdaptAddr);
if (NULL == (pAdaptAddr = (IP_ADAPTER_ADDRESSES*)MALLOC(dwSize)))
return NULL;
dwRet = GetAdaptersAddresses(dwFamily,
GAA_FLAG_SKIP_UNICAST \
| GAA_FLAG_SKIP_ANYCAST \
| GAA_FLAG_SKIP_MULTICAST \
| GAA_FLAG_SKIP_DNS_SERVER,
NULL,
pAdaptAddr,
&dwSize
);
}
if (NO_ERROR == dwRet) {
pTmpAdaptAddr = pAdaptAddr;
while (pTmpAdaptAddr) {
if (pTmpAdaptAddr -> IfIndex == ifindex) {
ifname = cyginet_ifname(pTmpAdaptAddr -> AdapterName);
break;
}
pTmpAdaptAddr = pTmpAdaptAddr->Next;
}
FREE(pAdaptAddr);
}
return ifname;
}
/* /*
* There are 3 ways to dump route table in the Windows: * There are 3 ways to dump route table in the Windows:
* *
...@@ -1493,6 +1492,62 @@ cyginet_ifname(const char * guidname) ...@@ -1493,6 +1492,62 @@ cyginet_ifname(const char * guidname)
/* The following functions are reserved. */ /* The following functions are reserved. */
#if 0 #if 0
static int
libwinet_get_loopback_index(int family)
{
IP_ADAPTER_ADDRESSES *pAdaptAddr = NULL;
IP_ADAPTER_ADDRESSES *pTmpAdaptAddr = NULL;
DWORD dwRet = 0;
DWORD dwSize = 0x10000;
DWORD dwReturn = 0;
dwRet = GetAdaptersAddresses(family,
GAA_FLAG_SKIP_ANYCAST \
| GAA_FLAG_SKIP_MULTICAST \
| GAA_FLAG_SKIP_DNS_SERVER \
| GAA_FLAG_SKIP_FRIENDLY_NAME,
NULL,
pAdaptAddr,
&dwSize
);
if (ERROR_BUFFER_OVERFLOW == dwRet) {
FREE(pAdaptAddr);
if (NULL == (pAdaptAddr = (IP_ADAPTER_ADDRESSES*)MALLOC(dwSize)))
return 0;
dwRet = GetAdaptersAddresses(family,
GAA_FLAG_SKIP_ANYCAST \
| GAA_FLAG_SKIP_MULTICAST \
| GAA_FLAG_SKIP_DNS_SERVER \
| GAA_FLAG_SKIP_FRIENDLY_NAME,
NULL,
pAdaptAddr,
&dwSize
);
}
if (NO_ERROR == dwRet) {
pTmpAdaptAddr = pAdaptAddr;
while (pTmpAdaptAddr) {
if (IF_TYPE_SOFTWARE_LOOPBACK == pTmpAdaptAddr -> IfType) {
dwReturn = family == AF_INET ?
pTmpAdaptAddr -> IfIndex :
pTmpAdaptAddr -> Ipv6IfIndex;
/* Loopback interface doesn't support both of Ipv4 or Ipv6 */
if (dwReturn)
break;
}
pTmpAdaptAddr = pTmpAdaptAddr->Next;
}
FREE(pAdaptAddr);
}
return dwReturn;
}
static PMIB_IPFORWARDTABLE static PMIB_IPFORWARDTABLE
libwinet_get_ipforward_table(int forder) libwinet_get_ipforward_table(int forder)
{ {
...@@ -2288,6 +2343,15 @@ runTestCases() ...@@ -2288,6 +2343,15 @@ runTestCases()
} }
} }
printf("\n\nTest cyginet_ipv4_index2ifname:\n\n");
{
int ifindex = 1;
printf("The name of ipv4 ifindex %d: %s\n",
ifindex,
cyginet_ipv4_index2ifname(ifindex)
);
}
printf("\n\nTest cyginet_guidname works in the Cygwin:\n\n"); printf("\n\nTest cyginet_guidname works in the Cygwin:\n\n");
{ {
PLIBWINET_INTERFACE_MAP_TABLE p = interface_map_table; PLIBWINET_INTERFACE_MAP_TABLE p = interface_map_table;
...@@ -2329,6 +2393,7 @@ runTestCases() ...@@ -2329,6 +2393,7 @@ runTestCases()
#endif /* _WIN32_WINNT < _WIN32_WINNT_VISTA */ #endif /* _WIN32_WINNT < _WIN32_WINNT_VISTA */
/*
printf("\n\nTest libwinet_get_loopback_index:\n\n"); printf("\n\nTest libwinet_get_loopback_index:\n\n");
{ {
printf("Ipv4 loopback ifindex is %d\n", printf("Ipv4 loopback ifindex is %d\n",
...@@ -2338,6 +2403,7 @@ runTestCases() ...@@ -2338,6 +2403,7 @@ runTestCases()
libwinet_get_loopback_index(AF_INET6) libwinet_get_loopback_index(AF_INET6)
); );
} }
*/
printf("\n\nTest cyginet_set_ipv6_forwards:\n\n"); printf("\n\nTest cyginet_set_ipv6_forwards:\n\n");
{ {
......
...@@ -151,9 +151,6 @@ extern void freeifaddrs(struct ifaddrs *); ...@@ -151,9 +151,6 @@ extern void freeifaddrs(struct ifaddrs *);
int cyginet_startup(); int cyginet_startup();
void cyginet_cleanup(); void cyginet_cleanup();
char * cyginet_ifname(const char *);
char * cyginet_guidname(const char *);
int cyginet_start_monitor_route_changes(int); int cyginet_start_monitor_route_changes(int);
int cyginet_stop_monitor_route_changes(); int cyginet_stop_monitor_route_changes();
int cyginet_set_ipv6_forwards(int); int cyginet_set_ipv6_forwards(int);
...@@ -175,4 +172,8 @@ int cyginet_delete_route_entry(const struct sockaddr *, unsigned short, ...@@ -175,4 +172,8 @@ int cyginet_delete_route_entry(const struct sockaddr *, unsigned short,
int cyginet_update_route_entry(const struct sockaddr *, unsigned short, int cyginet_update_route_entry(const struct sockaddr *, unsigned short,
const struct sockaddr *, int , unsigned int); const struct sockaddr *, int , unsigned int);
char * cyginet_ifname(const char *);
char * cyginet_guidname(const char *);
char * cyginet_ipv4_index2ifname(int);
#endif /* __CYGIFNET_H__ */ #endif /* __CYGIFNET_H__ */
...@@ -494,8 +494,10 @@ print_kernel_route(int add, struct kernel_route *route) ...@@ -494,8 +494,10 @@ print_kernel_route(int add, struct kernel_route *route)
{ {
char *ifname = NULL; char *ifname = NULL;
char guidname[IFNAMSIZ]; char guidname[IFNAMSIZ];
if ((route->plen >= 96) && v4mapped(route->prefix)) {
if(if_indextoname(route->ifindex, guidname)) ifname = cyginet_ipv4_index2ifname(route->prefix);
}
else if(if_indextoname(route->ifindex, guidname))
ifname = cyginet_ifname(guidname); ifname = cyginet_ifname(guidname);
fprintf(stderr, fprintf(stderr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment