Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ivan Tyagov
slapos
Commits
7ca8acee
Commit
7ca8acee
authored
Feb 14, 2013
by
Jondy Zhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Windows XP doesn't support IPV6_V6ONLY options (net.c)
Fix issues to get the route table. Add README.cygwin
parent
5fe4e2ab
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
249 additions
and
157 deletions
+249
-157
component/babeld/README.cygwin
component/babeld/README.cygwin
+52
-0
component/babeld/cyginet.c
component/babeld/cyginet.c
+123
-98
component/babeld/cyginet.h
component/babeld/cyginet.h
+6
-10
component/babeld/kernel_cygwin.c
component/babeld/kernel_cygwin.c
+66
-48
component/babeld/net.c
component/babeld/net.c
+2
-1
No files found.
component/babeld/README.cygwin
0 → 100644
View file @
7ca8acee
Introduction
============
Babeld for windows can work in the Cygwin 1.7 and later.
Changed files
-------------
Makefile
net.c
kernel.c
New files
---------
kernel_cygwin.c
cyginet.h
cyginet.c
README.cygwin
Building in the cygwin
======================
Required packages:
Cygwin 1.7
gcc 4.5.3 for cygwin
In the Windows XP,
$ PLATFORM_DEFINES="-D_WIN32_WINNT=0x0503" make
Later Windows Vista,
$ PLATFORM_DEFINES="-D_WIN32_WINNT=0x0600" make
Interface Names
===============
In the Windows, GUID is used as unique interface names. You can list
all the interfaces by the following command:
$ ipv6 if | grep "^Interface" -A 1
--
Interface 2: Automatic Tunneling Pseudo-Interface
Guid {48FCE3FC-EC30-E50E-F1A7-71172AEEE3AE}
--
Interface 1: Loopback Pseudo-Interface
Guid {6BD113CC-5EC2-7638-B953-0B889DA72014}
...
When call babled, use GUID as interface name:
$ ./babeld.exe {6BD113CC-5EC2-7638-B953-0B889DA72014}
component/babeld/cyginet.c
View file @
7ca8acee
...
@@ -202,9 +202,8 @@ libwinet_run_command(const char *command)
...
@@ -202,9 +202,8 @@ libwinet_run_command(const char *command)
* Gateway could be an address or interface name.
* Gateway could be an address or interface name.
*
*
*/
*/
static
int
static
int
libwinet_dump_ipv6_route_table
(
struct
kernel
_route
*
routes
,
libwinet_dump_ipv6_route_table
(
struct
cyginet
_route
*
routes
,
int
maxroutes
)
int
maxroutes
)
{
{
#define MAX_LINE_SIZE 80
#define MAX_LINE_SIZE 80
...
@@ -216,13 +215,19 @@ libwinet_dump_ipv6_route_table(struct kernel_route *routes,
...
@@ -216,13 +215,19 @@ libwinet_dump_ipv6_route_table(struct kernel_route *routes,
int
count
=
0
;
int
count
=
0
;
int
ignored
=
0
;
int
ignored
=
0
;
IN6_ADDR
*
sin6
;
struct
sockaddr_in6
*
dest
;
struct
kernel_route
*
proute
=
routes
;
struct
sockaddr_in6
*
gate
;
struct
cyginet_route
route
;
struct
cyginet_route
*
proute
=
routes
;
output
=
popen
(
command
,
"r"
);
output
=
popen
(
command
,
"r"
);
if
(
!
output
)
if
(
!
output
)
return
-
1
;
return
-
1
;
dest
=
(
struct
sockaddr_in6
*
)
&
(
route
.
prefix
);
gate
=
(
struct
sockaddr_in6
*
)
&
(
route
.
gateway
);
/* Ignore the first line */
/* Ignore the first line */
fgets
(
buffer
,
MAX_LINE_SIZE
,
output
);
fgets
(
buffer
,
MAX_LINE_SIZE
,
output
);
...
@@ -240,41 +245,43 @@ libwinet_dump_ipv6_route_table(struct kernel_route *routes,
...
@@ -240,41 +245,43 @@ libwinet_dump_ipv6_route_table(struct kernel_route *routes,
/* The first field of route entry */
/* The first field of route entry */
if
(
strncmp
(
buffer
,
"Prefix"
,
6
)
==
0
)
{
if
(
strncmp
(
buffer
,
"Prefix"
,
6
)
==
0
)
{
sin6
=
(
IN6_ADDR
*
)
&
(
proute
->
prefix
);
memset
(
&
route
,
0
,
sizeof
(
struct
cyginet_route
));
if
(
NULL
==
(
p
=
strchr
(
s
,
'/'
)))
if
(
NULL
==
(
p
=
strchr
(
s
,
'/'
)))
break
;
break
;
*
p
++
=
0
;
*
p
++
=
0
;
/*
/*
* Maybe it will be "fe80::5efe:10.85.0.127", ignore it
* Maybe it will be "fe80::5efe:10.85.0.127", ignore it
*/
*/
if
(
inet_pton
(
AF_INET6
,
s
,
sin6
)
!=
1
)
if
(
inet_pton
(
AF_INET6
,
s
,
&
(
dest
->
sin6_addr
)
)
!=
1
)
ignored
=
1
;
ignored
=
1
;
proute
->
plen
=
strtol
(
p
,
NULL
,
10
);
dest
->
sin6_family
=
AF_INET6
;
route
.
plen
=
strtol
(
p
,
NULL
,
10
);
}
}
else
if
(
strncmp
(
buffer
,
"Interface"
,
9
)
==
0
)
else
if
(
strncmp
(
buffer
,
"Interface"
,
9
)
==
0
)
proute
->
ifindex
=
strtol
(
buffer
+
9
,
NULL
,
10
);
route
.
ifindex
=
strtol
(
buffer
+
9
,
NULL
,
10
);
else
if
(
strncmp
(
buffer
,
"Gateway"
,
7
)
==
0
)
{
else
if
(
strncmp
(
buffer
,
"Gateway"
,
7
)
==
0
)
{
sin6
=
(
IN6_ADDR
*
)
&
(
proute
->
gw
);
if
(
inet_pton
(
AF_INET6
,
s
,
&
(
gate
->
sin6_addr
))
==
1
)
if
(
inet_pton
(
AF_INET6
,
s
,
sin6
)
!=
1
)
gate
->
sin6_family
=
AF_INET6
;
memset
(
sin6
,
0
,
sizeof
(
IN6_ADDR
));
}
}
else
if
(
strncmp
(
buffer
,
"Metric"
,
6
)
==
0
)
else
if
(
strncmp
(
buffer
,
"Metric"
,
6
)
==
0
)
proute
->
metric
=
strtol
(
s
,
NULL
,
10
);
route
.
metric
=
strtol
(
s
,
NULL
,
10
);
/* Last field of the route entry */
/* Last field of the route entry */
else
if
(
strncmp
(
buffer
,
"Site Prefix Length"
,
18
)
==
0
)
{
else
if
(
strncmp
(
buffer
,
"Site Prefix Length"
,
18
)
==
0
)
{
if
(
ignored
)
if
(
ignored
)
ignored
=
0
;
ignored
=
0
;
else
if
(
!
ignored
)
{
else
if
(
!
ignored
)
{
proute
->
proto
=
MIB_IPPROTO_OTHER
;
/* ?? */
route
.
proto
=
MIB_IPPROTO_OTHER
;
/* ?? */
if
((
maxroutes
>
count
)
&&
(
proute
!=
NULL
))
{
memcpy
(
proute
,
&
route
,
sizeof
(
struct
cyginet_route
));
proute
++
;
}
count
++
;
count
++
;
proute
++
;
if
(
count
>
maxroutes
)
break
;
}
}
}
}
...
@@ -1015,31 +1022,6 @@ cyginet_loopback_index(int family)
...
@@ -1015,31 +1022,6 @@ cyginet_loopback_index(int family)
return
libwinet_get_loopback_index
(
family
);
return
libwinet_get_loopback_index
(
family
);
}
}
static
PMIB_IPFORWARDTABLE
libwinet_get_ipforward_table
(
int
forder
)
{
DWORD
dwSize
=
0
;
PMIB_IPFORWARDTABLE
pIpForwardTable
;
pIpForwardTable
=
(
PMIB_IPFORWARDTABLE
)
MALLOC
(
sizeof
(
MIB_IPFORWARDTABLE
));
if
(
NULL
==
pIpForwardTable
)
return
NULL
;
if
(
ERROR_INSUFFICIENT_BUFFER
==
GetIpForwardTable
(
pIpForwardTable
,
&
dwSize
,
forder
))
{
FREE
(
pIpForwardTable
);
pIpForwardTable
=
(
PMIB_IPFORWARDTABLE
)
MALLOC
(
dwSize
);
if
(
pIpForwardTable
==
NULL
)
return
NULL
;
}
if
(
NO_ERROR
==
GetIpForwardTable
(
pIpForwardTable
,
&
dwSize
,
forder
))
return
pIpForwardTable
;
return
NULL
;
}
/*
/*
* There are 3 ways to dump route table in the Windows:
* There are 3 ways to dump route table in the Windows:
*
*
...
@@ -1057,18 +1039,18 @@ libwinet_get_ipforward_table(int forder)
...
@@ -1057,18 +1039,18 @@ libwinet_get_ipforward_table(int forder)
*
*
*/
*/
int
int
cyginet_dump_route_table
(
struct
kernel
_route
*
routes
,
int
maxroutes
)
cyginet_dump_route_table
(
struct
cyginet
_route
*
routes
,
int
maxroutes
)
{
{
ULONG
NumEntries
=
-
1
;
ULONG
NumEntries
=
-
1
;
struct
kernel
_route
*
proute
;
struct
cyginet
_route
*
proute
;
int
i
;
int
i
;
#if _WIN32_WINNT < _WIN32_WINNT_VISTA
#if _WIN32_WINNT < _WIN32_WINNT_VISTA
/* First dump ipv6 route */
/* First dump ipv6 route */
NumEntries
=
libwinet_dump_ipv6_route_table
(
routes
,
maxroutes
);
NumEntries
=
libwinet_dump_ipv6_route_table
(
routes
,
maxroutes
);
if
(
NumEntries
<
0
)
if
(
NumEntries
<
0
)
return
-
1
;
return
-
1
;
...
@@ -1076,40 +1058,56 @@ cyginet_dump_route_table(struct kernel_route *routes, int maxroutes)
...
@@ -1076,40 +1058,56 @@ cyginet_dump_route_table(struct kernel_route *routes, int maxroutes)
SOCKADDR_IN
*
paddr
;
SOCKADDR_IN
*
paddr
;
PMIB_IPFORWARDTABLE
pIpForwardTable
;
PMIB_IPFORWARDTABLE
pIpForwardTable
;
PMIB_IPFORWARDROW
pRow
;
PMIB_IPFORWARDROW
pRow
;
if
(
NULL
==
(
pIpForwardTable
=
libwinet_get_ipforward_table
(
0
)))
DWORD
dwSize
=
sizeof
(
MIB_IPFORWARDTABLE
);
pIpForwardTable
=
(
PMIB_IPFORWARDTABLE
)
MALLOC
(
dwSize
);
if
(
NULL
==
pIpForwardTable
)
return
-
1
;
return
-
1
;
{
if
(
ERROR_INSUFFICIENT_BUFFER
==
GetIpForwardTable
(
pIpForwardTable
,
proute
=
routes
+
NumEntries
;
&
dwSize
,
NumEntries
+=
pIpForwardTable
->
dwNumEntries
;
0
if
(
NumEntries
>
maxroutes
)
{
))
{
FREE
(
pIpForwardTable
);
FREE
(
pIpForwardTable
);
pIpForwardTable
=
(
PMIB_IPFORWARDTABLE
)
MALLOC
(
dwSize
);
if
(
pIpForwardTable
==
NULL
)
return
-
1
;
return
-
1
;
}
}
pRow
=
pIpForwardTable
->
table
;
if
(
NO_ERROR
!=
GetIpForwardTable
(
pIpForwardTable
,
for
(
i
=
0
;
&
dwSize
,
i
<
(
int
)
pIpForwardTable
->
dwNumEntries
;
0
))
i
++
,
proute
++
,
pRow
++
)
{
return
-
1
;
/* libwinet_map_ifindex_to_ipv6ifindex */
proute
->
ifindex
=
pRow
->
dwForwardIfIndex
;
proute
->
metric
=
pRow
->
dwForwardMetric1
;
proute
->
proto
=
pRow
->
dwForwardProto
;
proute
->
plen
=
mask2len
((
unsigned
char
*
)
&
(
pRow
->
dwForwardMask
),
4
);
/* Note that the IPv4 addresses returned in GetIpForwardTable
* entries are in network byte order
*/
paddr
=
(
SOCKADDR_IN
*
)
proute
->
prefix
;
paddr
->
sin_family
=
AF_INET
;
(
paddr
->
sin_addr
).
S_un
.
S_addr
=
pRow
->
dwForwardDest
;
paddr
=
(
SOCKADDR_IN
*
)
proute
->
gw
;
proute
=
routes
+
NumEntries
;
paddr
->
sin_family
=
AF_INET
;
(
paddr
->
sin_addr
).
S_un
.
S_addr
=
pRow
->
dwForwardNextHop
;
NumEntries
+=
pIpForwardTable
->
dwNumEntries
;
}
if
((
routes
==
NULL
)
||
(
NumEntries
>
maxroutes
))
{
FREE
(
pIpForwardTable
);
FREE
(
pIpForwardTable
);
return
NumEntries
;
}
pRow
=
pIpForwardTable
->
table
;
for
(
i
=
0
;
i
<
(
int
)
pIpForwardTable
->
dwNumEntries
;
i
++
,
proute
++
,
pRow
++
)
{
/* libwinet_map_ifindex_to_ipv6ifindex */
proute
->
ifindex
=
pRow
->
dwForwardIfIndex
;
proute
->
metric
=
pRow
->
dwForwardMetric1
;
proute
->
proto
=
pRow
->
dwForwardProto
;
proute
->
plen
=
mask2len
((
unsigned
char
*
)
&
(
pRow
->
dwForwardMask
),
4
);
/* Note that the IPv4 addresses returned in GetIpForwardTable
* entries are in network byte order
*/
paddr
=
(
struct
sockaddr_in
*
)
&
(
proute
->
prefix
);
paddr
->
sin_family
=
AF_INET
;
(
paddr
->
sin_addr
).
S_un
.
S_addr
=
pRow
->
dwForwardDest
;
paddr
=
(
struct
sockaddr_in
*
)
&
(
proute
->
gateway
);
paddr
->
sin_family
=
AF_INET
;
(
paddr
->
sin_addr
).
S_un
.
S_addr
=
pRow
->
dwForwardNextHop
;
}
}
FREE
(
pIpForwardTable
);
#else
#else
PMIB_IPFORWARD_TABLE2
pIpForwardTable2
;
PMIB_IPFORWARD_TABLE2
pIpForwardTable2
;
...
@@ -1120,27 +1118,29 @@ cyginet_dump_route_table(struct kernel_route *routes, int maxroutes)
...
@@ -1120,27 +1118,29 @@ cyginet_dump_route_table(struct kernel_route *routes, int maxroutes)
pIpForwardTable2
pIpForwardTable2
0
))
{
0
))
{
if
(
pIpForwardTable2
->
NumEntries
<
maxroutes
)
{
NumEntries
=
pIpForwardTable2
->
dwNumEntries
;
if
((
routes
==
NULL
)
||
(
NumEntries
>
maxroutes
))
{
proute
=
routes
+
NumEntries
;
FreeMibTable
(
pIpForwardTable2
);
NumEntries
=
pIpForwardTable2
->
dwNumEntries
;
return
NumEntries
;
pRow2
=
pIpForwardTable2
->
Table
;
}
for
(
i
=
0
;
i
<
NumEntries
;
i
++
,
proute
++
,
pRow2
++
)
{
proute
->
ifindex
=
pRow2
->
InterfaceIndex
;
proute
->
metric
=
pRow2
->
Metric
;
proute
->
proto
=
pRow2
->
Protocol
;
proute
->
plen
=
(
pRow2
->
DestinationPrefix
).
PrefixLength
;
memcpy
(
proute
->
prefix
,
(
pRow2
->
DestinationPrefix
).
DestinationPrefix
,
sizeof
(
SOCKADDR_INET
)
);
memcpy
(
proute
->
gw
,
pRow2
->
NextHop
,
sizeof
(
SOCKADDR_INET
)
);
}
proute
=
routes
;
NumEntries
=
pIpForwardTable2
->
dwNumEntries
;
pRow2
=
pIpForwardTable2
->
Table
;
for
(
i
=
0
;
i
<
NumEntries
;
i
++
,
proute
++
,
pRow2
++
)
{
proute
->
ifindex
=
pRow2
->
InterfaceIndex
;
proute
->
metric
=
pRow2
->
Metric
;
proute
->
proto
=
pRow2
->
Protocol
;
proute
->
plen
=
(
pRow2
->
DestinationPrefix
).
PrefixLength
;
memcpy
(
proute
->
prefix
,
(
pRow2
->
DestinationPrefix
).
DestinationPrefix
,
sizeof
(
SOCKADDR_INET
)
);
memcpy
(
proute
->
gateway
,
pRow2
->
NextHop
,
sizeof
(
SOCKADDR_INET
)
);
}
}
FreeMibTable
(
pIpForwardTable2
);
FreeMibTable
(
pIpForwardTable2
);
}
}
...
@@ -1209,6 +1209,31 @@ void cyginet_cleanup()
...
@@ -1209,6 +1209,31 @@ void cyginet_cleanup()
/* The following functions are reserved. */
/* The following functions are reserved. */
#if 0
#if 0
static PMIB_IPFORWARDTABLE
libwinet_get_ipforward_table(int forder)
{
DWORD dwSize = sizeof(MIB_IPFORWARDTABLE);
PMIB_IPFORWARDTABLE pIpForwardTable;
pIpForwardTable = (PMIB_IPFORWARDTABLE)MALLOC(dwSize);
if (NULL == pIpForwardTable)
return NULL;
if (ERROR_INSUFFICIENT_BUFFER == GetIpForwardTable(pIpForwardTable,
&dwSize,
forder
)) {
FREE(pIpForwardTable);
pIpForwardTable = (PMIB_IPFORWARDTABLE) MALLOC(dwSize);
if (pIpForwardTable == NULL)
return NULL;
}
if (NO_ERROR == GetIpForwardTable(pIpForwardTable,
&dwSize,
forder))
return pIpForwardTable;
return NULL;
}
static int
static int
convert_ipv6_route_table2()
convert_ipv6_route_table2()
{
{
...
@@ -1969,8 +1994,8 @@ runTestCases()
...
@@ -1969,8 +1994,8 @@ runTestCases()
printf
(
"
\n\n
Test libwinet_dump_ipv6_route_table:
\n\n
"
);
printf
(
"
\n\n
Test libwinet_dump_ipv6_route_table:
\n\n
"
);
{
{
struct
kernel
_route
routes
[
100
];
struct
cyginet
_route
routes
[
100
];
memset
(
routes
,
0
,
sizeof
(
struct
kernel
_route
)
*
100
);
memset
(
routes
,
0
,
sizeof
(
struct
cyginet
_route
)
*
100
);
int
n
=
libwinet_dump_ipv6_route_table
(
routes
,
100
);
int
n
=
libwinet_dump_ipv6_route_table
(
routes
,
100
);
printf
(
"Get route numbers: %d
\n
"
,
n
);
printf
(
"Get route numbers: %d
\n
"
,
n
);
}
}
...
@@ -2182,8 +2207,8 @@ runTestCases()
...
@@ -2182,8 +2207,8 @@ runTestCases()
printf
(
"
\n\n
Test cyginet_dump_route_table:
\n\n
"
);
printf
(
"
\n\n
Test cyginet_dump_route_table:
\n\n
"
);
do
{
do
{
#define MAX_ROUTES 120
#define MAX_ROUTES 120
struct
kernel
_route
routes
[
MAX_ROUTES
];
struct
cyginet
_route
routes
[
MAX_ROUTES
];
memset
(
routes
,
0
,
sizeof
(
struct
kernel
_route
)
*
MAX_ROUTES
);
memset
(
routes
,
0
,
sizeof
(
struct
cyginet
_route
)
*
MAX_ROUTES
);
int
n
=
cyginet_dump_route_table
(
routes
,
MAX_ROUTES
);
int
n
=
cyginet_dump_route_table
(
routes
,
MAX_ROUTES
);
printf
(
"Get route numbers: %d
\n
"
,
n
);
printf
(
"Get route numbers: %d
\n
"
,
n
);
}
while
(
0
);
}
while
(
0
);
...
...
component/babeld/cyginet.h
View file @
7ca8acee
...
@@ -75,20 +75,16 @@ struct sockaddr_dl {
...
@@ -75,20 +75,16 @@ struct sockaddr_dl {
contains both if name and ll address */
contains both if name and ll address */
};
};
#if defined(INSIDE_CYGINET)
struct
cyginet_route
{
struct
sockaddr
prefix
;
/* Copy from babeld/kernel.h */
#define RTPROT_BABEL_LOCAL -2
#define KERNEL_INFINITY 0xFFFF
struct
kernel_route
{
unsigned
char
prefix
[
16
];
int
plen
;
int
plen
;
int
metric
;
int
metric
;
unsigned
int
ifindex
;
unsigned
int
ifindex
;
int
proto
;
int
proto
;
unsigned
char
gw
[
16
]
;
struct
sockaddr
gateway
;
};
};
/* End of Copy */
#if defined(INSIDE_CYGINET)
struct
ifaddrs
{
struct
ifaddrs
{
struct
ifaddrs
*
ifa_next
;
struct
ifaddrs
*
ifa_next
;
...
@@ -156,7 +152,7 @@ int cyginet_interface_mtu(const char *, int);
...
@@ -156,7 +152,7 @@ int cyginet_interface_mtu(const char *, int);
int
cyginet_interface_operational
(
const
char
*
,
int
);
int
cyginet_interface_operational
(
const
char
*
,
int
);
int
cyginet_interface_ipv4
(
const
char
*
,
int
,
unsigned
char
*
);
int
cyginet_interface_ipv4
(
const
char
*
,
int
,
unsigned
char
*
);
int
cyginet_dump_route_table
(
struct
kernel
_route
*
,
int
);
int
cyginet_dump_route_table
(
struct
cyginet
_route
*
,
int
);
int
cyginet_loopback_index
(
int
);
int
cyginet_loopback_index
(
int
);
int
cyginet_add_route_entry
(
const
struct
sockaddr
*
,
unsigned
short
,
int
cyginet_add_route_entry
(
const
struct
sockaddr
*
,
unsigned
short
,
...
...
component/babeld/kernel_cygwin.c
View file @
7ca8acee
...
@@ -59,7 +59,7 @@ THE SOFTWARE.
...
@@ -59,7 +59,7 @@ THE SOFTWARE.
* 3. kernel_interface_ipv4
* 3. kernel_interface_ipv4
*
*
* ? interface name, ipv4, ifindex, Oh, they're mass.
* ? interface name, ipv4, ifindex, Oh, they're mass.
*
*
*/
*/
static
int
get_sdl
(
struct
sockaddr_dl
*
sdl
,
char
*
ifname
);
static
int
get_sdl
(
struct
sockaddr_dl
*
sdl
,
char
*
ifname
);
...
@@ -125,10 +125,10 @@ kernel_setup(int setup)
...
@@ -125,10 +125,10 @@ kernel_setup(int setup)
int
accept_redirects
=
0
;
int
accept_redirects
=
0
;
int
reboot
=
0
;
int
reboot
=
0
;
/* It enables ip6.forwarding and disable ip6.redirect.
/* It enables ip6.forwarding and disable ip6.redirect.
*
*
* Option 1:
* Option 1:
*
*
* IPV6CTL_FORWARDING (ip6.forwarding) Boolean: enable/disable
* IPV6CTL_FORWARDING (ip6.forwarding) Boolean: enable/disable
* forward- ing of IPv6 packets. Also, identify if the node is
* forward- ing of IPv6 packets. Also, identify if the node is
* acting as a router. Defaults to off.
* acting as a router. Defaults to off.
...
@@ -136,7 +136,7 @@ kernel_setup(int setup)
...
@@ -136,7 +136,7 @@ kernel_setup(int setup)
* ==> command line:
* ==> command line:
*
*
* C:/> ipv6 ifc $If6Index forwards
* C:/> ipv6 ifc $If6Index forwards
*
*
* repeat this operation for all ipv6 interfaces
* repeat this operation for all ipv6 interfaces
*
*
* List all ipv6 interface by the command:
* List all ipv6 interface by the command:
...
@@ -155,13 +155,13 @@ kernel_setup(int setup)
...
@@ -155,13 +155,13 @@ kernel_setup(int setup)
*
*
* A value of 1 enables TCP/IP forwarding for all network
* A value of 1 enables TCP/IP forwarding for all network
* connections that are installed and used by this computer.
* connections that are installed and used by this computer.
*
*
* Refer to: http://support.microsoft.com/kb/315236/en-us
* Refer to: http://support.microsoft.com/kb/315236/en-us
*
*
* Option 2:
* Option 2:
*
*
* ICMPV6CTL_REDIRACCEPT
* ICMPV6CTL_REDIRACCEPT
*
*
* IPV6CTL_SENDREDIRECTS (ip6.redirect) Boolean: enable/disable
* IPV6CTL_SENDREDIRECTS (ip6.redirect) Boolean: enable/disable
* sending of ICMPv6 redirects in response to unforwardable IPv6
* sending of ICMPv6 redirects in response to unforwardable IPv6
* packets. This option is ignored unless the node is routing
* packets. This option is ignored unless the node is routing
...
@@ -171,26 +171,26 @@ kernel_setup(int setup)
...
@@ -171,26 +171,26 @@ kernel_setup(int setup)
* ==> MSDN says in the registry
* ==> MSDN says in the registry
*
*
* HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
* HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
*
*
* EnableICMPRedirect = 0
* EnableICMPRedirect = 0
*
*
* Refer to:
* Refer to:
*
*
* http://technet.microsoft.com/en-us/library/cc766102(v=ws.10).aspx
* http://technet.microsoft.com/en-us/library/cc766102(v=ws.10).aspx
*
*
* After change them, need to reboot machine.
* After change them, need to reboot machine.
*
*
* Notice:
* Notice:
*
*
* MSDN says nothing about ipv6, it should use the following key
* MSDN says nothing about ipv6, it should use the following key
*
*
* HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters
* HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters
*
*
* Maybe later Window VISTA its corresponding APIs are
* Maybe later Window VISTA its corresponding APIs are
* WSAEnumProtocols, WSCUpdateProvider.
* WSAEnumProtocols, WSCUpdateProvider.
*
*
*/
*/
if
(
setup
)
{
if
(
setup
)
{
int
flags
;
int
flags
;
if
(
0
!=
cyginet_startup
())
if
(
0
!=
cyginet_startup
())
...
@@ -207,7 +207,7 @@ kernel_setup(int setup)
...
@@ -207,7 +207,7 @@ kernel_setup(int setup)
if
(
reboot
)
if
(
reboot
)
cyginet_set_ipv6_forwards
(
old_forwarding
);
cyginet_set_ipv6_forwards
(
old_forwarding
);
return
-
1
;
return
-
1
;
}
}
old_accept_redirects
=
rc
;
old_accept_redirects
=
rc
;
reboot
=
(
rc
==
accept_redirects
)
?
reboot
:
1
;
reboot
=
(
rc
==
accept_redirects
)
?
reboot
:
1
;
if
(
pipe
(
kernel_pipe_handles
)
==
-
1
)
if
(
pipe
(
kernel_pipe_handles
)
==
-
1
)
...
@@ -226,12 +226,12 @@ kernel_setup(int setup)
...
@@ -226,12 +226,12 @@ kernel_setup(int setup)
return
-
1
;
return
-
1
;
reboot
=
(
rc
==
accept_redirects
)
?
reboot
:
1
;
reboot
=
(
rc
==
accept_redirects
)
?
reboot
:
1
;
close
(
kernel_pipe_handles
[
0
]);
close
(
kernel_pipe_handles
[
0
]);
close
(
kernel_pipe_handles
[
1
]);
close
(
kernel_pipe_handles
[
1
]);
cyginet_cleanup
();
cyginet_cleanup
();
}
}
if
(
reboot
)
if
(
reboot
)
fprintf
(
stderr
,
fprintf
(
stderr
,
"%s IPv6 forwarding and %s ICMPv6 redirect successfully.
\n
"
"%s IPv6 forwarding and %s ICMPv6 redirect successfully.
\n
"
"REBOOT NOW, so that these changes take effect.
\n\n
"
,
"REBOOT NOW, so that these changes take effect.
\n\n
"
,
forwarding
?
"Enable"
:
"Disable"
,
forwarding
?
"Enable"
:
"Disable"
,
...
@@ -280,7 +280,7 @@ kernel_interface_operational(const char *ifname, int ifindex)
...
@@ -280,7 +280,7 @@ kernel_interface_operational(const char *ifname, int ifindex)
{
{
int
rc
;
int
rc
;
int
flags
=
link_detect
?
(
IFF_UP
|
IFF_RUNNING
)
:
IFF_UP
;
int
flags
=
link_detect
?
(
IFF_UP
|
IFF_RUNNING
)
:
IFF_UP
;
rc
=
cyginet_interface_operational
(
ifname
,
ifindex
);
rc
=
cyginet_interface_operational
(
ifname
,
ifindex
);
if
(
rc
<
0
)
if
(
rc
<
0
)
return
-
1
;
return
-
1
;
...
@@ -312,22 +312,22 @@ kernel_interface_channel(const char *ifname, int ifindex)
...
@@ -312,22 +312,22 @@ kernel_interface_channel(const char *ifname, int ifindex)
return
-
1
;
return
-
1
;
}
}
/*
/*
* RTF_REJECT
* RTF_REJECT
*
*
* Instead of forwarding a packet like a normal route, routes with
* Instead of forwarding a packet like a normal route, routes with
* RTF_REJECT cause packets to be dropped and unreachable messages
* RTF_REJECT cause packets to be dropped and unreachable messages
* to be sent to the packet originators. This flag is only valid on
* to be sent to the packet originators. This flag is only valid on
* routes pointing at the loopback interface.
* routes pointing at the loopback interface.
*
*
* RTF_BLACKHOLE
* RTF_BLACKHOLE
*
*
* Like the RTF_REJECT flag, routes with RTF_BLACKHOLE cause packets
* Like the RTF_REJECT flag, routes with RTF_BLACKHOLE cause packets
* to be dropped, but unreachable messages are not sent. This flag
* to be dropped, but unreachable messages are not sent. This flag
* is only valid on routes pointing at the loopback interface.
* is only valid on routes pointing at the loopback interface.
*
*
* Nullrouting on Windows
* Nullrouting on Windows
*
*
* Windows XP/Vista/7 does not support reject or blackhole arguments
* Windows XP/Vista/7 does not support reject or blackhole arguments
* via route, thus an unused IP address (e.g. 192.168.0.205) must be
* via route, thus an unused IP address (e.g. 192.168.0.205) must be
* used as the target gateway.
* used as the target gateway.
...
@@ -336,12 +336,12 @@ kernel_interface_channel(const char *ifname, int ifindex)
...
@@ -336,12 +336,12 @@ kernel_interface_channel(const char *ifname, int ifindex)
*
*
* RTF_HOST: host entry (net otherwise)
* RTF_HOST: host entry (net otherwise)
*
*
* It means all the netmask bits are 1.
* It means all the netmask bits are 1.
*
*
* RTF_CLONING: generate new routes on use
* RTF_CLONING: generate new routes on use
*
*
* No corresponding function in the Windows.
* No corresponding function in the Windows.
*
*
*/
*/
int
int
kernel_route
(
int
operation
,
const
unsigned
char
*
dest
,
unsigned
short
plen
,
kernel_route
(
int
operation
,
const
unsigned
char
*
dest
,
unsigned
short
plen
,
...
@@ -374,7 +374,7 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen,
...
@@ -374,7 +374,7 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen,
ipv4
=
0
;
ipv4
=
0
;
}
}
if
(
operation
==
ROUTE_MODIFY
&&
newmetric
==
metric
&&
if
(
operation
==
ROUTE_MODIFY
&&
newmetric
==
metric
&&
memcmp
(
newgate
,
gate
,
16
)
==
0
&&
newifindex
==
ifindex
)
memcmp
(
newgate
,
gate
,
16
)
==
0
&&
newifindex
==
ifindex
)
return
0
;
return
0
;
...
@@ -443,20 +443,20 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen,
...
@@ -443,20 +443,20 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen,
if(IN6_IS_ADDR_LINKLOCAL (&sin6->sin6_addr)) \
if(IN6_IS_ADDR_LINKLOCAL (&sin6->sin6_addr)) \
SET_IN6_LINKLOCAL_IFINDEX (sin6->sin6_addr, ifindex); \
SET_IN6_LINKLOCAL_IFINDEX (sin6->sin6_addr, ifindex); \
} while (0)
} while (0)
if
(
ipv4
)
{
if
(
ipv4
)
{
PUSHADDR
(
destination
,
dest
);
PUSHADDR
(
destination
,
dest
);
if
(
metric
==
KERNEL_INFINITY
)
if
(
metric
==
KERNEL_INFINITY
)
PUSHADDR
(
gateway
,
**
local4
);
PUSHADDR
(
gateway
,
**
local4
);
else
else
PUSHADDR
(
gateway
,
gate
);
PUSHADDR
(
gateway
,
gate
);
}
else
{
}
else
{
PUSHADDR6
(
destination
,
dest
);
PUSHADDR6
(
destination
,
dest
);
if
(
metric
==
KERNEL_INFINITY
)
if
(
metric
==
KERNEL_INFINITY
)
PUSHADDR6
(
gateway
,
&
local6
);
PUSHADDR6
(
gateway
,
&
local6
);
else
else
PUSHADDR6
(
gateway
,
gate
);
PUSHADDR6
(
gateway
,
gate
);
}
}
#undef PUSHADDR
#undef PUSHADDR
...
@@ -519,7 +519,7 @@ print_kernel_route(int add, struct kernel_route *route)
...
@@ -519,7 +519,7 @@ print_kernel_route(int add, struct kernel_route *route)
}
}
static
int
static
int
parse_kernel_route
(
struct
kernel_route
*
route
)
parse_kernel_route
(
struct
cyginet_route
*
src
,
struct
kernel_route
*
route
)
{
{
struct
sockaddr
*
sa
;
struct
sockaddr
*
sa
;
...
@@ -535,9 +535,16 @@ parse_kernel_route(struct kernel_route *route)
...
@@ -535,9 +535,16 @@ parse_kernel_route(struct kernel_route *route)
return
-
1
;
return
-
1
;
}
}
sa
=
(
struct
sockaddr
*
)
route
->
prefix
;
memset
(
route
,
0
,
sizeof
(
struct
kernel_route
));
route
->
plen
=
src
->
plen
;
route
->
metric
=
src
->
metric
;
route
->
proto
=
src
->
proto
;
route
->
ifindex
=
src
->
ifindex
;
sa
=
&
(
src
->
prefix
);
if
(
sa
->
sa_family
==
AF_INET6
)
{
if
(
sa
->
sa_family
==
AF_INET6
)
{
struct
sockaddr_in6
*
sin6
=
(
struct
sockaddr_in6
*
)
sa
;
struct
sockaddr_in6
*
sin6
=
(
struct
sockaddr_in6
*
)
sa
;
memcpy
(
route
->
prefix
,
&
sin6
->
sin6_addr
,
16
);
if
(
IN6_IS_ADDR_LINKLOCAL
(
&
sin6
->
sin6_addr
)
if
(
IN6_IS_ADDR_LINKLOCAL
(
&
sin6
->
sin6_addr
)
||
IN6_IS_ADDR_MC_LINKLOCAL
(
&
sin6
->
sin6_addr
))
||
IN6_IS_ADDR_MC_LINKLOCAL
(
&
sin6
->
sin6_addr
))
return
-
1
;
return
-
1
;
...
@@ -555,9 +562,10 @@ parse_kernel_route(struct kernel_route *route)
...
@@ -555,9 +562,10 @@ parse_kernel_route(struct kernel_route *route)
}
}
/* Gateway */
/* Gateway */
sa
=
(
struct
sockaddr
*
)
route
->
gw
;
sa
=
&
(
src
->
gateway
)
;
if
(
sa
->
sa_family
==
AF_INET6
)
{
if
(
sa
->
sa_family
==
AF_INET6
)
{
struct
sockaddr_in6
*
sin6
=
(
struct
sockaddr_in6
*
)
sa
;
struct
sockaddr_in6
*
sin6
=
(
struct
sockaddr_in6
*
)
sa
;
memcpy
(
route
->
gw
,
&
sin6
->
sin6_addr
,
16
);
if
(
IN6_IS_ADDR_LINKLOCAL
(
&
sin6
->
sin6_addr
))
{
if
(
IN6_IS_ADDR_LINKLOCAL
(
&
sin6
->
sin6_addr
))
{
route
->
ifindex
=
IN6_LINKLOCAL_IFINDEX
(
sin6
->
sin6_addr
);
route
->
ifindex
=
IN6_LINKLOCAL_IFINDEX
(
sin6
->
sin6_addr
);
SET_IN6_LINKLOCAL_IFINDEX
(
sin6
->
sin6_addr
,
0
);
SET_IN6_LINKLOCAL_IFINDEX
(
sin6
->
sin6_addr
,
0
);
...
@@ -567,7 +575,7 @@ parse_kernel_route(struct kernel_route *route)
...
@@ -567,7 +575,7 @@ parse_kernel_route(struct kernel_route *route)
v4tov6
(
route
->
gw
,
(
unsigned
char
*
)
&
sin
->
sin_addr
);
v4tov6
(
route
->
gw
,
(
unsigned
char
*
)
&
sin
->
sin_addr
);
}
}
if
((
sa
->
sa_family
==
AF_INET6
)
&&
(
route
->
ifindex
==
if6index_lo
))
if
((
sa
->
sa_family
==
AF_INET6
)
&&
(
route
->
ifindex
==
if6index_lo
))
return
-
1
;
return
-
1
;
if
((
sa
->
sa_family
==
AF_INET
)
&&
(
route
->
ifindex
==
ifindex_lo
))
if
((
sa
->
sa_family
==
AF_INET
)
&&
(
route
->
ifindex
==
ifindex_lo
))
return
-
1
;
return
-
1
;
...
@@ -583,30 +591,40 @@ kernel_routes(struct kernel_route *routes, int maxroutes)
...
@@ -583,30 +591,40 @@ kernel_routes(struct kernel_route *routes, int maxroutes)
{
{
int
rc
,
i
;
int
rc
,
i
;
int
count
;
int
count
;
struct
kernel_route
*
proute
=
routes
;
struct
kernel_route
*
proute
=
routes
;
struct
kernel_route
*
pdest
=
proute
;
struct
cyginet_route
*
ptable
;
memset
(
routes
,
0
,
sizeof
(
struct
kernel_route
)
*
maxroutes
);
rc
=
cyginet_dump_route_table
(
routes
,
maxroutes
);
rc
=
cyginet_dump_route_table
(
NULL
,
0
);
if
(
rc
<
0
)
if
(
rc
<
0
)
return
-
1
;
return
-
1
;
if
(
rc
==
0
)
return
0
;
rc
+=
10
;
if
(
NULL
==
(
ptable
=
calloc
(
rc
,
sizeof
(
struct
cyginet_route
))))
return
-
1
;
rc
=
cyginet_dump_route_table
(
ptable
,
rc
);
if
(
rc
<
0
)
{
free
(
ptable
);
return
-
1
;
}
count
=
0
;
for
(
i
=
0
,
count
=
0
;
i
<
rc
;
i
++
)
{
for
(
i
=
0
;
i
<
rc
;
i
++
,
proute
++
)
{
if
(
parse_kernel_route
(
proute
)
!=
0
)
if
(
parse_kernel_route
(
p
table
+
i
,
p
route
)
!=
0
)
continue
;
continue
;
if
(
proute
!=
pdest
)
memcpy
(
pdest
,
proute
,
sizeof
(
struct
kernel_route
));
if
(
debug
>
2
)
if
(
debug
>
2
)
print_kernel_route
(
RTM_ADD
,
p
dest
);
print_kernel_route
(
RTM_ADD
,
p
route
);
pdest
++
;
if
(
maxroutes
>
rc
)
proute
++
;
count
++
;
}
}
return
(
pdest
-
routes
);
free
(
ptable
);
return
count
;
}
}
int
int
...
...
component/babeld/net.c
View file @
7ca8acee
...
@@ -19,7 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
...
@@ -19,7 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
*/
*/
#include <unistd.h>
#include <unistd.h>
#include <stdio.h>
#include <stdio.h>
#include <fcntl.h>
#include <fcntl.h>
...
@@ -50,9 +49,11 @@ babel_socket(int port)
...
@@ -50,9 +49,11 @@ babel_socket(int port)
if
(
s
<
0
)
if
(
s
<
0
)
return
-
1
;
return
-
1
;
#if !defined(_WIN32_WINNT) || _WIN32_WINNT >= 0x0600
rc
=
setsockopt
(
s
,
IPPROTO_IPV6
,
IPV6_V6ONLY
,
&
one
,
sizeof
(
one
));
rc
=
setsockopt
(
s
,
IPPROTO_IPV6
,
IPV6_V6ONLY
,
&
one
,
sizeof
(
one
));
if
(
rc
<
0
)
if
(
rc
<
0
)
goto
fail
;
goto
fail
;
#endif
rc
=
setsockopt
(
s
,
SOL_SOCKET
,
SO_REUSEADDR
,
&
one
,
sizeof
(
one
));
rc
=
setsockopt
(
s
,
SOL_SOCKET
,
SO_REUSEADDR
,
&
one
,
sizeof
(
one
));
if
(
rc
<
0
)
if
(
rc
<
0
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment