Commit 0f224483 authored by Jondy Zhao's avatar Jondy Zhao

Restore metric from 1 to 0;

Restore KERNEL_IFINITY from 9999 to 0xFFFF;
Add function libwinet_map_ifindex used to map interface index
between ipv4 and ipv6.
parent 3a55d749
...@@ -14,20 +14,15 @@ SRCS = babeld.c net.c kernel.c util.c interface.c source.c neighbour.c \ ...@@ -14,20 +14,15 @@ SRCS = babeld.c net.c kernel.c util.c interface.c source.c neighbour.c \
OBJS = babeld.o net.o kernel.o util.o interface.o source.o neighbour.o \ OBJS = babeld.o net.o kernel.o util.o interface.o source.o neighbour.o \
route.o xroute.o message.o resend.o configuration.o local.o route.o xroute.o message.o resend.o configuration.o local.o
KERNEL_SOUCES = kernel_netlink.c kernel_socket.c
ifneq "$(WINVER)" "" ifneq "$(WINVER)" ""
SRCS += cyginet.c SRCS += cyginet.c
OBJS += cyginet.o OBJS += cyginet.o
LDLIBS += -liphlpapi -lws2_32 -lwlanapi -lole32 -lsetupapi LDLIBS += -liphlpapi -lws2_32 -lwlanapi -lole32 -lsetupapi
KERNEL_SOUCES += kernel_cygwin.c
ifeq "$(WINVER)" "XP" ifeq "$(WINVER)" "XP"
CFLAGS += -D_WIN32_WINNT=0x0503 CFLAGS += -D_WIN32_WINNT=0x0503
endif else
ifeq "$(WINVER)" "VISTA"
CLFAGS += -D_WIN32_WINNT=0x0600 CLFAGS += -D_WIN32_WINNT=0x0600
endif endif
...@@ -67,7 +62,7 @@ uninstall: ...@@ -67,7 +62,7 @@ uninstall:
clean: 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_netlink.c kernel_socket.c kernel_cygwin.c
# Usage: ./testc.exe # Usage: ./testc.exe
# Verify most of the functions in the cyginet.c # Verify most of the functions in the cyginet.c
......
...@@ -229,6 +229,59 @@ libwinet_refresh_interface_map_table() ...@@ -229,6 +229,59 @@ libwinet_refresh_interface_map_table()
return (NO_ERROR == dwRet); return (NO_ERROR == dwRet);
} }
static int
libwinet_map_ifindex(int family, int ifindex)
{
IP_ADAPTER_ADDRESSES *pAdaptAddr = NULL;
IP_ADAPTER_ADDRESSES *pTmpAdaptAddr = NULL;
DWORD dwRet = 0;
DWORD dwSize = 0x10000;
DWORD dwReturn = 0;
dwRet = GetAdaptersAddresses(AF_UNSPEC,
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(AF_UNSPEC,
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 (family == AF_INET ? pTmpAdaptAddr -> IfIndex == ifindex
: pTmpAdaptAddr -> Ipv6IfIndex == ifindex) {
dwReturn = family == AF_INET ?
pTmpAdaptAddr -> Ipv6IfIndex : pTmpAdaptAddr -> IfIndex;
break;
}
pTmpAdaptAddr = pTmpAdaptAddr->Next;
}
FREE(pAdaptAddr);
}
return dwReturn;
}
static int static int
libwinet_get_interface_info(const char *ifname, libwinet_get_interface_info(const char *ifname,
PLIBWINET_INTERFACE pinfo) PLIBWINET_INTERFACE pinfo)
...@@ -320,7 +373,6 @@ static int ...@@ -320,7 +373,6 @@ 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)
...@@ -788,7 +840,7 @@ libwinet_edit_route_entry(const struct sockaddr *dest, ...@@ -788,7 +840,7 @@ libwinet_edit_route_entry(const struct sockaddr *dest,
Row.dwForwardDest = (((SOCKADDR_IN*)dest) -> sin_addr).S_un.S_addr; Row.dwForwardDest = (((SOCKADDR_IN*)dest) -> sin_addr).S_un.S_addr;
Row.dwForwardPolicy = 0; Row.dwForwardPolicy = 0;
Row.dwForwardNextHop = (((SOCKADDR_IN*)gate) -> sin_addr).S_un.S_addr; Row.dwForwardNextHop = (((SOCKADDR_IN*)gate) -> sin_addr).S_un.S_addr;
Row.dwForwardIfIndex = ifindex; Row.dwForwardIfIndex = libwinet_map_ifindex(AF_INET6, ifindex);
/* /*
* MIB_IPROUTE_TYPE_DIRECT <==> dwForwardNextHop == dwForwardDest * MIB_IPROUTE_TYPE_DIRECT <==> dwForwardNextHop == dwForwardDest
* MIB_IPROUTE_TYPE_LOCAL <==> dwForwardNextHop == Ip of the interface * MIB_IPROUTE_TYPE_LOCAL <==> dwForwardNextHop == Ip of the interface
...@@ -864,7 +916,7 @@ libwinet_edit_route_entry(const struct sockaddr *dest, ...@@ -864,7 +916,7 @@ libwinet_edit_route_entry(const struct sockaddr *dest,
smask, smask,
sgate, sgate,
metric, metric,
ifindex libwinet_map_ifindex(AF_INET6, ifindex)
) >= MAX_BUFFER_SIZE) ) >= MAX_BUFFER_SIZE)
return -1; return -1;
...@@ -880,7 +932,9 @@ libwinet_edit_route_entry(const struct sockaddr *dest, ...@@ -880,7 +932,9 @@ libwinet_edit_route_entry(const struct sockaddr *dest,
memset(&Row2, 0, sizeof(MIB_IPFORWARDROW2)); memset(&Row2, 0, sizeof(MIB_IPFORWARDROW2));
Row2.InterfaceLuid = NULL; Row2.InterfaceLuid = NULL;
Row2.InterfaceIndex = ifindex; /* Maybe in the Vista, both of indexs are same. */
Row2.InterfaceIndex = dest->sa_family == AF_INET6 ?
ifindex : libwinet_map_ifindex(AF_INET6, ifindex);
Row2.DestinationPrefix.PrefixLength = plen; Row2.DestinationPrefix.PrefixLength = plen;
memcpy(&Row2.DestinationPrefix.Prefix, dest, sizeof(SOCKADDR_INET)); memcpy(&Row2.DestinationPrefix.Prefix, dest, sizeof(SOCKADDR_INET));
memcpy(&Row2.NextHop, gate, sizeof(SOCKADDR_INET)) ; memcpy(&Row2.NextHop, gate, sizeof(SOCKADDR_INET)) ;
...@@ -1339,8 +1393,8 @@ cyginet_dump_route_table(struct cyginet_route *routes, int maxroutes) ...@@ -1339,8 +1393,8 @@ cyginet_dump_route_table(struct cyginet_route *routes, int maxroutes)
for (i = 0; for (i = 0;
i < (int) pIpForwardTable->dwNumEntries; i < (int) pIpForwardTable->dwNumEntries;
i++, proute ++, pRow ++) { i++, proute ++, pRow ++) {
/* Here the ifindex is the index of ipv4 interface */ /* Map Ipv4 ifindex to Ipv6 Ifindex, maybe return 0 */
proute -> ifindex = pRow -> dwForwardIfIndex; proute -> ifindex = libwinet_map_ifindex(AF_INET, pRow -> dwForwardIfIndex);
proute -> metric = pRow -> dwForwardMetric1; proute -> metric = pRow -> dwForwardMetric1;
proute -> proto = pRow -> dwForwardProto; proute -> proto = pRow -> dwForwardProto;
proute -> plen = mask2len((unsigned char*)&(pRow -> dwForwardMask), 4); proute -> plen = mask2len((unsigned char*)&(pRow -> dwForwardMask), 4);
...@@ -1818,58 +1872,6 @@ convert_ipv6_route_table_to_rtm(struct rt_msghdr *rtm, ...@@ -1818,58 +1872,6 @@ convert_ipv6_route_table_to_rtm(struct rt_msghdr *rtm,
return start; return start;
} }
static int
libwinet_map_ifindex_to_ipv6ifindex(int ifindex)
{
IP_ADAPTER_ADDRESSES *pAdaptAddr = NULL;
IP_ADAPTER_ADDRESSES *pTmpAdaptAddr = NULL;
DWORD dwRet = 0;
DWORD dwSize = 0x10000;
DWORD dwReturn = 0;
DWORD Family = AF_UNSPEC;
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 (pTmpAdaptAddr -> IfIndex == ifindex) {
dwReturn = pTmpAdaptAddr -> Ipv6IfIndex;
break;
}
pTmpAdaptAddr = pTmpAdaptAddr->Next;
}
FREE(pAdaptAddr);
}
return dwReturn;
}
static ULONG static ULONG
convert_time_from_string_to_ulong(const char * stime) convert_time_from_string_to_ulong(const char * stime)
{ {
...@@ -2405,6 +2407,21 @@ runTestCases() ...@@ -2405,6 +2407,21 @@ runTestCases()
} }
*/ */
printf("\n\nTest libwinet_map_ifindex:\n\n");
{
int i;
for (i = 1; i < 32; i++) {
printf("Ipv4 ifindex %d map to: Ipv6 index %d\n",
i,
libwinet_map_ifindex(AF_INET, i)
);
printf("Ipv6 ifindex %d map to: Ipv4 index %d\n",
i,
libwinet_map_ifindex(AF_INET6, i)
);
}
}
printf("\n\nTest cyginet_set_ipv6_forwards:\n\n"); printf("\n\nTest cyginet_set_ipv6_forwards:\n\n");
{ {
printf("cyginet_set_ipv6_forwards(1) return %d\n", printf("cyginet_set_ipv6_forwards(1) return %d\n",
......
...@@ -23,11 +23,7 @@ THE SOFTWARE. ...@@ -23,11 +23,7 @@ THE SOFTWARE.
#include <netinet/in.h> #include <netinet/in.h>
#include "babeld.h" #include "babeld.h"
#if defined (_WIN32_WINNT)
#define KERNEL_INFINITY 9999
#else
#define KERNEL_INFINITY 0xFFFF #define KERNEL_INFINITY 0xFFFF
#endif
struct kernel_route { struct kernel_route {
unsigned char prefix[16]; unsigned char prefix[16];
......
...@@ -494,10 +494,7 @@ print_kernel_route(int add, struct kernel_route *route) ...@@ -494,10 +494,7 @@ 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,
...@@ -643,13 +640,6 @@ kernel_addresses(char *ifname, int ifindex, int ll, ...@@ -643,13 +640,6 @@ kernel_addresses(char *ifname, int ifindex, int ll,
ifap = ifa; ifap = ifa;
i = 0; i = 0;
/* In the Linux, metric is set to 0, but it's invalid in the
Windows, so we set metric to 1 here.
And gateway to be set as 0 in the Linux, as the same reason, we
set it as prefix in the Windows.
*/
while(ifap && i < maxroutes) { while(ifap && i < maxroutes) {
if((ifname != NULL && compare_ifname(ifap->ifa_name, ifname) != 0)) if((ifname != NULL && compare_ifname(ifap->ifa_name, ifname) != 0))
goto next; goto next;
...@@ -664,7 +654,7 @@ kernel_addresses(char *ifname, int ifindex, int ll, ...@@ -664,7 +654,7 @@ kernel_addresses(char *ifname, int ifindex, int ll,
reset those bytes to 0 before passing them to babeld. */ reset those bytes to 0 before passing them to babeld. */
memset(routes[i].prefix + 2, 0, 2); memset(routes[i].prefix + 2, 0, 2);
routes[i].plen = 128; routes[i].plen = 128;
routes[i].metric = 1; routes[i].metric = 0;
routes[i].ifindex = ifindex; routes[i].ifindex = ifindex;
routes[i].proto = RTPROT_BABEL_LOCAL; routes[i].proto = RTPROT_BABEL_LOCAL;
memcpy(routes[i].gw, routes[i].prefix, 16); memcpy(routes[i].gw, routes[i].prefix, 16);
...@@ -680,7 +670,7 @@ kernel_addresses(char *ifname, int ifindex, int ll, ...@@ -680,7 +670,7 @@ kernel_addresses(char *ifname, int ifindex, int ll,
memcpy(routes[i].prefix, v4prefix, 12); memcpy(routes[i].prefix, v4prefix, 12);
memcpy(routes[i].prefix + 12, &sin->sin_addr, 4); memcpy(routes[i].prefix + 12, &sin->sin_addr, 4);
routes[i].plen = 128; routes[i].plen = 128;
routes[i].metric = 1; routes[i].metric = 0;
routes[i].ifindex = ifindex; routes[i].ifindex = ifindex;
routes[i].proto = RTPROT_BABEL_LOCAL; routes[i].proto = RTPROT_BABEL_LOCAL;
memcpy(routes[i].gw, routes[i].prefix, 16); memcpy(routes[i].gw, routes[i].prefix, 16);
......
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