Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
babeld
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
babeld
Commits
fb7c6be0
Commit
fb7c6be0
authored
Jan 03, 2008
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement exporting of IPv4 routes.
parent
3880d2e5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
14 deletions
+29
-14
kernel_netlink.c
kernel_netlink.c
+29
-14
No files found.
kernel_netlink.c
View file @
fb7c6be0
...
@@ -503,9 +503,9 @@ kernel_setup_socket(int setup)
...
@@ -503,9 +503,9 @@ kernel_setup_socket(int setup)
int
rc
;
int
rc
;
if
(
setup
)
{
if
(
setup
)
{
rc
=
netlink_socket
(
&
nl_listen
,
RTMGRP_IPV6_ROUTE
);
rc
=
netlink_socket
(
&
nl_listen
,
RTMGRP_IPV6_ROUTE
|
RTMGRP_IPV4_ROUTE
);
if
(
rc
<
0
)
{
if
(
rc
<
0
)
{
perror
(
"netlink_socket(RTMGRP_
IPV6_
ROUTE)"
);
perror
(
"netlink_socket(RTMGRP_ROUTE)"
);
kernel_socket
=
-
1
;
kernel_socket
=
-
1
;
return
-
1
;
return
-
1
;
}
}
...
@@ -752,16 +752,27 @@ parse_kernel_route_rta(struct rtmsg *rtm, int len, struct kernel_route *route)
...
@@ -752,16 +752,27 @@ parse_kernel_route_rta(struct rtmsg *rtm, int len, struct kernel_route *route)
memset
(
&
route
->
prefix
,
0
,
sizeof
(
struct
in6_addr
));
memset
(
&
route
->
prefix
,
0
,
sizeof
(
struct
in6_addr
));
memset
(
&
route
->
gw
,
0
,
sizeof
(
struct
in6_addr
));
memset
(
&
route
->
gw
,
0
,
sizeof
(
struct
in6_addr
));
route
->
plen
=
rtm
->
rtm_dst_len
;
route
->
plen
=
rtm
->
rtm_dst_len
;
if
(
rtm
->
rtm_family
==
AF_INET
)
route
->
plen
+=
96
;
route
->
metric
=
KERNEL_INFINITY
;
route
->
metric
=
KERNEL_INFINITY
;
route
->
ifindex
=
0
;
route
->
ifindex
=
0
;
#define COPY_ADDR(d, s) \
do { \
if(rtm->rtm_family == AF_INET6) \
memcpy(d, s, 16); \
else if(rtm->rtm_family == AF_INET) \
v4tov6(d, s); \
else \
return -1; \
} while(0)
while
(
RTA_OK
(
rta
,
len
))
{
while
(
RTA_OK
(
rta
,
len
))
{
switch
(
rta
->
rta_type
)
{
switch
(
rta
->
rta_type
)
{
case
RTA_DST
:
case
RTA_DST
:
memcpy
(
&
route
->
prefix
,
RTA_DATA
(
rta
),
16
);
COPY_ADDR
(
route
->
prefix
,
RTA_DATA
(
rta
)
);
break
;
break
;
case
RTA_GATEWAY
:
case
RTA_GATEWAY
:
memcpy
(
&
route
->
gw
,
RTA_DATA
(
rta
),
16
);
COPY_ADDR
(
route
->
gw
,
RTA_DATA
(
rta
)
);
break
;
break
;
case
RTA_OIF
:
case
RTA_OIF
:
route
->
ifindex
=
*
(
int
*
)
RTA_DATA
(
rta
);
route
->
ifindex
=
*
(
int
*
)
RTA_DATA
(
rta
);
...
@@ -779,6 +790,7 @@ parse_kernel_route_rta(struct rtmsg *rtm, int len, struct kernel_route *route)
...
@@ -779,6 +790,7 @@ parse_kernel_route_rta(struct rtmsg *rtm, int len, struct kernel_route *route)
}
}
rta
=
RTA_NEXT
(
rta
,
len
);
rta
=
RTA_NEXT
(
rta
,
len
);
}
}
#undef COPY_ADDR
if
(
table
!=
RT_TABLE_MAIN
)
if
(
table
!=
RT_TABLE_MAIN
)
return
-
1
;
return
-
1
;
...
@@ -890,11 +902,12 @@ filter_kernel_routes(struct nlmsghdr *nh, void *data)
...
@@ -890,11 +902,12 @@ filter_kernel_routes(struct nlmsghdr *nh, void *data)
int
int
kernel_routes
(
int
maxplen
,
struct
kernel_route
*
routes
,
int
maxroutes
)
kernel_routes
(
int
maxplen
,
struct
kernel_route
*
routes
,
int
maxroutes
)
{
{
int
rc
;
int
i
,
rc
;
int
maxp
=
maxplen
;
int
maxp
=
maxplen
;
int
maxr
=
maxroutes
;
int
maxr
=
maxroutes
;
int
found
=
0
;
int
found
=
0
;
void
*
data
[
4
]
=
{
&
maxp
,
&
maxr
,
routes
,
&
found
};
void
*
data
[
4
]
=
{
&
maxp
,
&
maxr
,
routes
,
&
found
};
int
families
[
2
]
=
{
AF_INET6
,
AF_INET
};
struct
rtgenmsg
g
;
struct
rtgenmsg
g
;
if
(
!
nl_setup
)
{
if
(
!
nl_setup
)
{
...
@@ -911,8 +924,9 @@ kernel_routes(int maxplen, struct kernel_route *routes, int maxroutes)
...
@@ -911,8 +924,9 @@ kernel_routes(int maxplen, struct kernel_route *routes, int maxroutes)
}
}
}
}
for
(
i
=
0
;
i
<
2
;
i
++
)
{
memset
(
&
g
,
0
,
sizeof
(
g
));
memset
(
&
g
,
0
,
sizeof
(
g
));
g
.
rtgen_family
=
AF_INET6
;
g
.
rtgen_family
=
families
[
i
]
;
rc
=
netlink_send_dump
(
RTM_GETROUTE
,
&
g
,
sizeof
(
g
));
rc
=
netlink_send_dump
(
RTM_GETROUTE
,
&
g
,
sizeof
(
g
));
if
(
rc
<
0
)
if
(
rc
<
0
)
return
-
1
;
return
-
1
;
...
@@ -922,6 +936,7 @@ kernel_routes(int maxplen, struct kernel_route *routes, int maxroutes)
...
@@ -922,6 +936,7 @@ kernel_routes(int maxplen, struct kernel_route *routes, int maxroutes)
if
(
rc
<
0
)
if
(
rc
<
0
)
return
-
1
;
return
-
1
;
}
return
found
;
return
found
;
}
}
...
...
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