Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Host Manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
network
Host Manager
Commits
e6c66e4a
Commit
e6c66e4a
authored
3 months ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
add interface init helper funcs
To update ipaddrs, bridge info and mediatype
parent
cff12e95
Branches
Branches containing commit
No related tags found
1 merge request
!45
read assoclist from apmld object
Pipeline
#202680
passed
3 months ago
Stage: static_code_analysis
Stage: compile_test
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/hostmngr.c
+37
-54
37 additions, 54 deletions
src/hostmngr.c
with
37 additions
and
54 deletions
src/hostmngr.c
+
37
−
54
View file @
e6c66e4a
...
...
@@ -51,26 +51,9 @@ static void hostmngr_sighandler(int sig)
signal_pending
=
sig
;
}
struct
local_interface
*
hostmngr_alloc_interface
(
const
char
*
ifname
)
{
struct
local_interface
*
iface
=
NULL
;
struct
ip_address
ips
[
32
]
=
{
0
};
int
num_ipaddrs
=
32
;
int
ret
;
iface
=
calloc
(
1
,
sizeof
(
*
iface
));
if
(
!
iface
)
{
return
NULL
;
}
snprintf
(
iface
->
ifname
,
16
,
"%s"
,
ifname
);
iface
->
ifindex
=
if_nametoindex
(
ifname
);
dbg
(
"%s: %s (%d)
\n
"
,
__func__
,
iface
->
ifname
,
iface
->
ifindex
);
if_gethwaddr
(
ifname
,
iface
->
macaddr
);
if_getflags
(
ifname
,
&
iface
->
ifflags
);
if_getoperstate
(
ifname
,
&
iface
->
operstate
);
if_getcarrier
(
ifname
,
&
iface
->
carrier
);
static
void
hostmngr_update_interface_bridgeinfo
(
struct
local_interface
*
iface
)
{
iface
->
is_bridge
=
if_isbridge
(
iface
->
ifname
);
if
(
!
iface
->
is_bridge
)
{
int
br_ifindex
;
...
...
@@ -82,6 +65,13 @@ struct local_interface *hostmngr_alloc_interface(const char *ifname)
iface
->
br_ifindex
=
br_ifindex
;
}
}
}
static
void
hostmngr_update_interface_ipaddrs
(
struct
local_interface
*
iface
)
{
struct
ip_address
ips
[
32
]
=
{
0
};
int
num_ipaddrs
=
32
;
int
ret
;
ret
=
if_getaddrs
(
iface
->
ifname
,
ips
,
&
num_ipaddrs
);
if
(
!
ret
&&
num_ipaddrs
>
0
)
{
...
...
@@ -91,7 +81,10 @@ struct local_interface *hostmngr_alloc_interface(const char *ifname)
memcpy
(
iface
->
ipaddrs
,
ips
,
num_ipaddrs
*
sizeof
(
struct
ip_address
));
}
}
}
static
void
hostmngr_update_interface_mediatype
(
struct
local_interface
*
iface
)
{
if
(
strncmp
(
iface
->
ifname
,
"lo"
,
2
))
{
if
(
is_wifi_interface
(
iface
->
ifname
))
{
iface
->
mediatype
=
IF_MEDIA_WIFI
;
...
...
@@ -100,12 +93,33 @@ struct local_interface *hostmngr_alloc_interface(const char *ifname)
iface
->
is_affiliated_ap
=
is_affiliated_ap
(
iface
->
ifname
);
if
(
iface
->
is_affiliated_ap
)
ap_get_mld_ifname
(
iface
->
ifname
,
iface
->
mld_ifname
);
}
}
else
{
iface
->
mediatype
=
IF_MEDIA_ETH
;
}
}
}
struct
local_interface
*
hostmngr_alloc_interface
(
const
char
*
ifname
)
{
struct
local_interface
*
iface
=
NULL
;
iface
=
calloc
(
1
,
sizeof
(
*
iface
));
if
(
!
iface
)
{
return
NULL
;
}
snprintf
(
iface
->
ifname
,
16
,
"%s"
,
ifname
);
iface
->
ifindex
=
if_nametoindex
(
ifname
);
dbg
(
"%s: %s (%d)
\n
"
,
__func__
,
iface
->
ifname
,
iface
->
ifindex
);
if_gethwaddr
(
ifname
,
iface
->
macaddr
);
if_getflags
(
ifname
,
&
iface
->
ifflags
);
if_getoperstate
(
ifname
,
&
iface
->
operstate
);
if_getcarrier
(
ifname
,
&
iface
->
carrier
);
hostmngr_update_interface_bridgeinfo
(
iface
);
hostmngr_update_interface_ipaddrs
(
iface
);
hostmngr_update_interface_mediatype
(
iface
);
return
iface
;
}
...
...
@@ -121,7 +135,6 @@ void enum_interfaces_cb(struct nl_object *obj, void *arg)
struct
rtnl_link
*
link
=
NULL
;
int
num_ipaddrs
=
32
;
struct
nl_addr
*
a
=
NULL
;
int
ret
;
nl_object_get
(
obj
);
...
...
@@ -147,40 +160,10 @@ void enum_interfaces_cb(struct nl_object *obj, void *arg)
iface
->
ifflags
=
rtnl_link_get_flags
(
link
);
iface
->
operstate
=
rtnl_link_get_operstate
(
link
);
iface
->
is_bridge
=
if_isbridge
(
iface
->
ifname
);
if
(
!
iface
->
is_bridge
)
{
int
br_ifindex
;
br_ifindex
=
if_isbridge_interface
(
iface
->
ifname
);
if
(
br_ifindex
>
0
)
{
iface
->
is_brif
=
true
;
iface
->
brport
=
if_brportnum
(
iface
->
ifname
);
iface
->
br_ifindex
=
br_ifindex
;
}
}
ret
=
if_getaddrs
(
iface
->
ifname
,
ips
,
&
num_ipaddrs
);
if
(
!
ret
&&
num_ipaddrs
>
0
)
{
iface
->
ipaddrs
=
calloc
(
num_ipaddrs
,
sizeof
(
struct
ip_address
));
if
(
iface
->
ipaddrs
)
{
iface
->
num_ipaddrs
=
num_ipaddrs
;
memcpy
(
iface
->
ipaddrs
,
ips
,
num_ipaddrs
*
sizeof
(
struct
ip_address
));
}
}
if
(
strncmp
(
iface
->
ifname
,
"lo"
,
2
))
{
if
(
is_wifi_interface
(
iface
->
ifname
))
{
iface
->
mediatype
=
IF_MEDIA_WIFI
;
if
(
is_ap_interface
(
iface
->
ifname
))
{
iface
->
is_ap
=
true
;
iface
->
is_affiliated_ap
=
is_affiliated_ap
(
iface
->
ifname
);
if
(
iface
->
is_affiliated_ap
)
ap_get_mld_ifname
(
iface
->
ifname
,
iface
->
mld_ifname
);
}
}
else
{
iface
->
mediatype
=
IF_MEDIA_ETH
;
}
}
hostmngr_update_interface_bridgeinfo
(
iface
);
hostmngr_update_interface_ipaddrs
(
iface
);
hostmngr_update_interface_mediatype
(
iface
);
list_add_tail
(
&
iface
->
list
,
argp
->
iflist
);
*
argp
->
n
+=
1
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment