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
4a973925
Commit
4a973925
authored
Jan 07, 2008
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use a single socket for all interface-related ioctls.
parent
92b5c602
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
25 deletions
+17
-25
kernel_netlink.c
kernel_netlink.c
+17
-25
No files found.
kernel_netlink.c
View file @
4a973925
...
@@ -53,6 +53,8 @@ static int old_ipv4_forwarding = -1;
...
@@ -53,6 +53,8 @@ static int old_ipv4_forwarding = -1;
static
int
old_accept_redirects
=
-
1
;
static
int
old_accept_redirects
=
-
1
;
static
int
old_rp_filter
=
-
1
;
static
int
old_rp_filter
=
-
1
;
static
int
dgram_socket
=
-
1
;
static
int
static
int
read_proc
(
char
*
filename
)
read_proc
(
char
*
filename
)
{
{
...
@@ -389,6 +391,10 @@ kernel_setup(int setup, int ipv4)
...
@@ -389,6 +391,10 @@ kernel_setup(int setup, int ipv4)
int
rc
;
int
rc
;
if
(
setup
)
{
if
(
setup
)
{
dgram_socket
=
socket
(
PF_INET
,
SOCK_DGRAM
,
0
);
if
(
dgram_socket
<
0
)
return
-
1
;
rc
=
netlink_socket
(
&
nl_command
,
0
);
rc
=
netlink_socket
(
&
nl_command
,
0
);
if
(
rc
<
0
)
{
if
(
rc
<
0
)
{
perror
(
"netlink_socket(0)"
);
perror
(
"netlink_socket(0)"
);
...
@@ -452,6 +458,9 @@ kernel_setup(int setup, int ipv4)
...
@@ -452,6 +458,9 @@ kernel_setup(int setup, int ipv4)
return
1
;
return
1
;
}
else
{
}
else
{
close
(
dgram_socket
);
dgram_socket
=
-
1
;
if
(
old_forwarding
>=
0
)
{
if
(
old_forwarding
>=
0
)
{
rc
=
write_proc
(
"/proc/sys/net/ipv6/conf/all/forwarding"
,
rc
=
write_proc
(
"/proc/sys/net/ipv6/conf/all/forwarding"
,
old_forwarding
);
old_forwarding
);
...
@@ -541,20 +550,14 @@ int
...
@@ -541,20 +550,14 @@ int
kernel_interface_ipv4
(
const
char
*
ifname
,
int
ifindex
,
char
*
addr_r
)
kernel_interface_ipv4
(
const
char
*
ifname
,
int
ifindex
,
char
*
addr_r
)
{
{
struct
ifreq
req
;
struct
ifreq
req
;
int
s
,
rc
;
int
rc
;
s
=
socket
(
PF_INET
,
SOCK_DGRAM
,
0
);
if
(
s
<
0
)
return
-
1
;
memset
(
&
req
,
0
,
sizeof
(
req
));
memset
(
&
req
,
0
,
sizeof
(
req
));
strncpy
(
req
.
ifr_name
,
ifname
,
sizeof
(
req
.
ifr_name
));
strncpy
(
req
.
ifr_name
,
ifname
,
sizeof
(
req
.
ifr_name
));
req
.
ifr_addr
.
sa_family
=
AF_INET
;
req
.
ifr_addr
.
sa_family
=
AF_INET
;
rc
=
ioctl
(
s
,
SIOCGIFADDR
,
&
req
);
rc
=
ioctl
(
dgram_socket
,
SIOCGIFADDR
,
&
req
);
if
(
rc
<
0
)
{
if
(
rc
<
0
)
close
(
s
);
return
-
1
;
return
-
1
;
}
memcpy
(
addr_r
,
&
((
struct
sockaddr_in
*
)
&
req
.
ifr_addr
)
->
sin_addr
,
4
);
memcpy
(
addr_r
,
&
((
struct
sockaddr_in
*
)
&
req
.
ifr_addr
)
->
sin_addr
,
4
);
return
1
;
return
1
;
...
@@ -564,19 +567,13 @@ int
...
@@ -564,19 +567,13 @@ int
kernel_interface_mtu
(
const
char
*
ifname
,
int
ifindex
)
kernel_interface_mtu
(
const
char
*
ifname
,
int
ifindex
)
{
{
struct
ifreq
req
;
struct
ifreq
req
;
int
s
,
rc
;
int
rc
;
s
=
socket
(
PF_INET
,
SOCK_DGRAM
,
0
);
if
(
s
<
0
)
return
-
1
;
memset
(
&
req
,
0
,
sizeof
(
req
));
memset
(
&
req
,
0
,
sizeof
(
req
));
strncpy
(
req
.
ifr_name
,
ifname
,
sizeof
(
req
.
ifr_name
));
strncpy
(
req
.
ifr_name
,
ifname
,
sizeof
(
req
.
ifr_name
));
rc
=
ioctl
(
s
,
SIOCGIFMTU
,
&
req
);
rc
=
ioctl
(
dgram_socket
,
SIOCGIFMTU
,
&
req
);
if
(
rc
<
0
)
{
if
(
rc
<
0
)
close
(
s
);
return
-
1
;
return
-
1
;
}
return
req
.
ifr_mtu
;
return
req
.
ifr_mtu
;
}
}
...
@@ -588,15 +585,11 @@ kernel_interface_wireless(const char *ifname, int ifindex)
...
@@ -588,15 +585,11 @@ kernel_interface_wireless(const char *ifname, int ifindex)
#define SIOCGIWNAME 0x8B01
#define SIOCGIWNAME 0x8B01
#endif
#endif
struct
ifreq
req
;
struct
ifreq
req
;
int
s
,
rc
;
int
rc
;
s
=
socket
(
PF_INET
,
SOCK_DGRAM
,
0
);
if
(
s
<
0
)
return
-
1
;
memset
(
&
req
,
0
,
sizeof
(
req
));
memset
(
&
req
,
0
,
sizeof
(
req
));
strncpy
(
req
.
ifr_name
,
ifname
,
sizeof
(
req
.
ifr_name
));
strncpy
(
req
.
ifr_name
,
ifname
,
sizeof
(
req
.
ifr_name
));
rc
=
ioctl
(
s
,
SIOCGIWNAME
,
&
req
);
rc
=
ioctl
(
dgram_socket
,
SIOCGIWNAME
,
&
req
);
if
(
rc
<
0
)
{
if
(
rc
<
0
)
{
if
(
errno
==
EOPNOTSUPP
||
errno
==
EINVAL
)
if
(
errno
==
EOPNOTSUPP
||
errno
==
EINVAL
)
rc
=
0
;
rc
=
0
;
...
@@ -607,7 +600,6 @@ kernel_interface_wireless(const char *ifname, int ifindex)
...
@@ -607,7 +600,6 @@ kernel_interface_wireless(const char *ifname, int ifindex)
}
else
{
}
else
{
rc
=
1
;
rc
=
1
;
}
}
close
(
s
);
return
rc
;
return
rc
;
}
}
...
...
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