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
b4990b38
Commit
b4990b38
authored
1 year ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
update iplist when assigning ipv4 addr
parent
9018e561
No related branches found
No related tags found
1 merge request
!24
Ipv4 addr
Pipeline
#134884
passed
1 year ago
Stage: static_code_analysis
Stage: compile_test
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/hostmngr.c
+31
-0
31 additions, 0 deletions
src/hostmngr.c
src/neigh.c
+14
-26
14 additions, 26 deletions
src/neigh.c
src/neigh.h
+1
-0
1 addition, 0 deletions
src/neigh.h
src/netlink.c
+15
-16
15 additions, 16 deletions
src/netlink.c
with
61 additions
and
42 deletions
src/hostmngr.c
+
31
−
0
View file @
b4990b38
...
@@ -457,6 +457,21 @@ void hostmngr_update_hostname_of_neighbors(struct hostmngr_private *priv,
...
@@ -457,6 +457,21 @@ void hostmngr_update_hostname_of_neighbors(struct hostmngr_private *priv,
e
->
leasetime
=
h
->
leasetime
;
e
->
leasetime
=
h
->
leasetime
;
e
->
ipv4_type_dhcp
=
1
;
e
->
ipv4_type_dhcp
=
1
;
if
(
!
neigh_is_ip_known
(
e
,
&
e
->
ipv4
))
{
struct
ip_address_entry
*
new
;
char
newip
[
64
]
=
{
0
};
inet_ntop
(
e
->
ipv4
.
family
,
&
e
->
ipv4
.
addr
,
newip
,
sizeof
(
newip
));
dbg
(
"%s: Adding new ipaddress %s to entry "
MACFMT
"
\n
"
,
__func__
,
newip
,
MAC2STR
(
e
->
macaddr
));
new
=
calloc
(
1
,
sizeof
(
*
new
));
if
(
new
)
{
memcpy
(
&
new
->
ip
,
&
e
->
ipv4
,
sizeof
(
e
->
ipv4
));
list_add_tail
(
&
new
->
list
,
&
e
->
iplist
);
}
}
ipn
=
neigh_ip_entry_lookup2
(
priv
,
&
e
->
ipv4
);
ipn
=
neigh_ip_entry_lookup2
(
priv
,
&
e
->
ipv4
);
if
(
ipn
)
{
if
(
ipn
)
{
ipn
->
neigh
=
e
;
ipn
->
neigh
=
e
;
...
@@ -507,6 +522,22 @@ int hostmngr_get_neigh_hostname(struct neigh_queue *q, uint8_t *macaddr)
...
@@ -507,6 +522,22 @@ int hostmngr_get_neigh_hostname(struct neigh_queue *q, uint8_t *macaddr)
e
->
ipv4_type_dhcp
=
1
;
e
->
ipv4_type_dhcp
=
1
;
e
->
ipv4_type_static
=
0
;
e
->
ipv4_type_static
=
0
;
if
(
!
neigh_is_ip_known
(
e
,
&
e
->
ipv4
))
{
struct
ip_address_entry
*
new
;
char
newip
[
64
]
=
{
0
};
inet_ntop
(
e
->
ipv4
.
family
,
&
e
->
ipv4
.
addr
,
newip
,
sizeof
(
newip
));
dbg
(
"%s: Adding new ipaddress %s to entry "
MACFMT
"
\n
"
,
__func__
,
newip
,
MAC2STR
(
e
->
macaddr
));
new
=
calloc
(
1
,
sizeof
(
*
new
));
if
(
new
)
{
memcpy
(
&
new
->
ip
,
&
e
->
ipv4
,
sizeof
(
e
->
ipv4
));
list_add_tail
(
&
new
->
list
,
&
e
->
iplist
);
}
}
ipn
=
neigh_ip_entry_lookup2
(
priv
,
&
e
->
ipv4
);
ipn
=
neigh_ip_entry_lookup2
(
priv
,
&
e
->
ipv4
);
if
(
ipn
)
{
if
(
ipn
)
{
ipn
->
neigh
=
e
;
ipn
->
neigh
=
e
;
...
...
This diff is collapsed.
Click to expand it.
src/neigh.c
+
14
−
26
View file @
b4990b38
...
@@ -1046,6 +1046,18 @@ bool is_neigh_1905_slave(void *nq, uint8_t *macaddr)
...
@@ -1046,6 +1046,18 @@ bool is_neigh_1905_slave(void *nq, uint8_t *macaddr)
return
is1905_slave
;
return
is1905_slave
;
}
}
bool
neigh_is_ip_known
(
struct
neigh_entry
*
e
,
struct
ip_address
*
ip
)
{
struct
ip_address_entry
*
ipaddr
=
NULL
;
list_for_each_entry
(
ipaddr
,
&
e
->
iplist
,
list
)
{
if
(
ipaddr_equal
(
&
ipaddr
->
ip
,
ip
))
return
true
;
}
return
false
;
}
int
neigh_is_wifi_type
(
void
*
priv
,
uint8_t
*
macaddr
)
int
neigh_is_wifi_type
(
void
*
priv
,
uint8_t
*
macaddr
)
{
{
struct
hostmngr_private
*
p
=
(
struct
hostmngr_private
*
)
priv
;
struct
hostmngr_private
*
p
=
(
struct
hostmngr_private
*
)
priv
;
...
@@ -1136,7 +1148,6 @@ struct neigh_entry *neigh_enqueue(void *nq, uint8_t *macaddr, uint16_t state,
...
@@ -1136,7 +1148,6 @@ struct neigh_entry *neigh_enqueue(void *nq, uint8_t *macaddr, uint16_t state,
e
=
neigh_lookup
(
nq
,
macaddr
);
e
=
neigh_lookup
(
nq
,
macaddr
);
if
(
e
)
{
if
(
e
)
{
struct
ip_address_entry
*
ipaddr
;
struct
ip_address_entry
*
ipaddr
;
bool
ipknown
=
false
;
dbg
(
"[%jd.%jd] Neigh "
MACFMT
" changed. ifname = %s, IP-family = %s, state 0x%04x -> 0x%04x
\n
"
,
dbg
(
"[%jd.%jd] Neigh "
MACFMT
" changed. ifname = %s, IP-family = %s, state 0x%04x -> 0x%04x
\n
"
,
(
uintmax_t
)
tsp
.
tv_sec
,
(
uintmax_t
)
tsp
.
tv_usec
,
MAC2STR
(
macaddr
),
(
uintmax_t
)
tsp
.
tv_sec
,
(
uintmax_t
)
tsp
.
tv_usec
,
MAC2STR
(
macaddr
),
...
@@ -1189,23 +1200,7 @@ struct neigh_entry *neigh_enqueue(void *nq, uint8_t *macaddr, uint16_t state,
...
@@ -1189,23 +1200,7 @@ struct neigh_entry *neigh_enqueue(void *nq, uint8_t *macaddr, uint16_t state,
}
}
if
(
ip
)
{
if
(
ip
)
{
/* can get overridden by dhcp lease entry */
if
(
!
neigh_is_ip_known
(
e
,
ip
))
{
if
(
ip
->
family
==
AF_INET
)
{
hostmngr_get_neigh_hostname
(
q
,
e
->
macaddr
);
if
(
!
ipaddr_equal
(
&
e
->
ipv4
,
ip
)
&&
(
e
->
ipv4_type_static
||
strlen
(
e
->
hostname
)))
{
memcpy
(
&
e
->
ipv4
,
ip
,
sizeof
(
*
ip
));
e
->
event_pending
=
0
;
hostmngr_host_event
(
priv
,
HOST_EVENT_CONNECT
,
e
);
}
}
list_for_each_entry
(
ipaddr
,
&
e
->
iplist
,
list
)
{
if
(
ipaddr_equal
(
&
ipaddr
->
ip
,
ip
))
ipknown
=
true
;
}
if
(
!
ipknown
)
{
struct
ip_address_entry
*
new
;
struct
ip_address_entry
*
new
;
char
newip
[
64
]
=
{
0
};
char
newip
[
64
]
=
{
0
};
...
@@ -1255,7 +1250,6 @@ struct neigh_entry *neigh_enqueue(void *nq, uint8_t *macaddr, uint16_t state,
...
@@ -1255,7 +1250,6 @@ struct neigh_entry *neigh_enqueue(void *nq, uint8_t *macaddr, uint16_t state,
if
(
e
)
{
if
(
e
)
{
int
idx
=
neigh_hash
(
macaddr
);
int
idx
=
neigh_hash
(
macaddr
);
struct
ip_address_entry
*
ipaddr
;
struct
ip_address_entry
*
ipaddr
;
bool
ipknown
=
false
;
hlist_add_head
(
&
e
->
hlist
,
&
q
->
table
[
idx
]);
hlist_add_head
(
&
e
->
hlist
,
&
q
->
table
[
idx
]);
...
@@ -1294,13 +1288,7 @@ struct neigh_entry *neigh_enqueue(void *nq, uint8_t *macaddr, uint16_t state,
...
@@ -1294,13 +1288,7 @@ struct neigh_entry *neigh_enqueue(void *nq, uint8_t *macaddr, uint16_t state,
if
(
ip
->
family
==
AF_INET
)
if
(
ip
->
family
==
AF_INET
)
memcpy
(
&
e
->
ipv4
,
ip
,
sizeof
(
*
ip
));
memcpy
(
&
e
->
ipv4
,
ip
,
sizeof
(
*
ip
));
if
(
!
neigh_is_ip_known
(
e
,
ip
))
{
list_for_each_entry
(
ipaddr
,
&
e
->
iplist
,
list
)
{
if
(
ipaddr_equal
(
&
ipaddr
->
ip
,
ip
))
ipknown
=
true
;
}
if
(
!
ipknown
)
{
struct
ip_address_entry
*
new
;
struct
ip_address_entry
*
new
;
dbg
(
"Adding new ipaddress to entry "
MACFMT
"
\n
"
,
dbg
(
"Adding new ipaddress to entry "
MACFMT
"
\n
"
,
...
...
This diff is collapsed.
Click to expand it.
src/neigh.h
+
1
−
0
View file @
b4990b38
...
@@ -196,6 +196,7 @@ int neigh_set_1905_linkaddr(void *nq, uint8_t *aladdr, uint8_t *linkaddr);
...
@@ -196,6 +196,7 @@ int neigh_set_1905_linkaddr(void *nq, uint8_t *aladdr, uint8_t *linkaddr);
bool
is_neigh_1905
(
void
*
q
,
uint8_t
*
macaddr
);
bool
is_neigh_1905
(
void
*
q
,
uint8_t
*
macaddr
);
bool
is_neigh_1905_slave
(
void
*
q
,
uint8_t
*
macaddr
);
bool
is_neigh_1905_slave
(
void
*
q
,
uint8_t
*
macaddr
);
bool
neigh_is_ip_known
(
struct
neigh_entry
*
e
,
struct
ip_address
*
ip
);
int
neigh_is_wifi_type
(
void
*
priv
,
uint8_t
*
macaddr
);
int
neigh_is_wifi_type
(
void
*
priv
,
uint8_t
*
macaddr
);
struct
neigh_entry
*
neigh_lookup
(
void
*
q
,
uint8_t
*
macaddr
);
struct
neigh_entry
*
neigh_lookup
(
void
*
q
,
uint8_t
*
macaddr
);
...
...
This diff is collapsed.
Click to expand it.
src/netlink.c
+
15
−
16
View file @
b4990b38
...
@@ -192,22 +192,6 @@ static int hostmngr_handle_neigh_tbl_change(struct hostmngr_private *priv, bool
...
@@ -192,22 +192,6 @@ static int hostmngr_handle_neigh_tbl_change(struct hostmngr_private *priv, bool
return
0
;
return
0
;
}
}
eh
=
neigh_history_lookup
(
&
priv
->
neigh_q
,
macaddr
);
if
(
eh
&&
eh
->
type
==
NEIGH_TYPE_WIFI
&&
eh
->
is1905
==
false
)
{
struct
neigh_entry
*
e
;
e
=
neigh_lookup
(
&
priv
->
neigh_q
,
macaddr
);
if
(
!
e
)
{
dbg
(
"Skip enqueue WiFi neigh through neigh table change
\n
"
);
return
0
;
}
if
(
e
->
event_pending
&&
!
ipaddr_is_zero
(
&
e
->
ipv4
)
&&
strlen
(
e
->
hostname
))
{
e
->
event_pending
=
0
;
hostmngr_host_event
(
priv
,
HOST_EVENT_CONNECT
,
e
);
}
}
new
=
neigh_enqueue
(
&
priv
->
neigh_q
,
macaddr
,
state
,
ifname
,
new
=
neigh_enqueue
(
&
priv
->
neigh_q
,
macaddr
,
state
,
ifname
,
NEIGH_TYPE_UNKNOWN
,
ip
,
NEIGH_AGEOUT_DEFAULT
,
NULL
);
NEIGH_TYPE_UNKNOWN
,
ip
,
NEIGH_AGEOUT_DEFAULT
,
NULL
);
...
@@ -225,6 +209,21 @@ static int hostmngr_handle_neigh_tbl_change(struct hostmngr_private *priv, bool
...
@@ -225,6 +209,21 @@ static int hostmngr_handle_neigh_tbl_change(struct hostmngr_private *priv, bool
}
}
eh
=
neigh_history_lookup
(
&
priv
->
neigh_q
,
macaddr
);
if
(
eh
&&
eh
->
type
==
NEIGH_TYPE_WIFI
&&
eh
->
is1905
==
false
)
{
struct
neigh_entry
*
e
;
e
=
neigh_lookup
(
&
priv
->
neigh_q
,
macaddr
);
if
(
!
e
)
{
dbg
(
"Skip enqueue WiFi neigh through neigh table change
\n
"
);
return
0
;
}
if
(
e
->
event_pending
&&
!
ipaddr_is_zero
(
&
e
->
ipv4
)
&&
strlen
(
e
->
hostname
))
{
e
->
event_pending
=
0
;
hostmngr_host_event
(
priv
,
HOST_EVENT_CONNECT
,
e
);
}
}
#if 0 //def NEIGH_DEBUG
#if 0 //def NEIGH_DEBUG
if (priv->neigh_q.pending_cnt > 0) {
if (priv->neigh_q.pending_cnt > 0) {
...
...
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