Skip to content
Snippets Groups Projects
Commit e8216213 authored by Anjan Chanda's avatar Anjan Chanda
Browse files

set primary ipv4 address correctly in static ip case

parent c07a0a37
Branches
No related tags found
No related merge requests found
Pipeline #101605 passed
......@@ -350,6 +350,7 @@ void topology_update_hostname_of_neighbors(struct topologyd_private *priv,
inet_aton(h->ipv4, &e->ipv4.addr.ip4);
e->ipv4.family = AF_INET;
e->leasetime = h->leasetime;
e->ipv4_type_dhcp = 1;
ipn = neigh_ip_entry_lookup2(priv, &e->ipv4);
if (ipn) {
......@@ -396,6 +397,7 @@ int topology_get_neigh_hostname(struct neigh_queue *q, uint8_t *macaddr)
inet_aton(h->ipv4, &e->ipv4.addr.ip4);
e->ipv4.family = AF_INET;
e->leasetime = h->leasetime;
e->ipv4_type_dhcp = 1;
ipn = neigh_ip_entry_lookup2(priv, &e->ipv4);
if (ipn) {
......
......@@ -835,6 +835,9 @@ struct neigh_entry *neigh_enqueue(void *nq, uint8_t *macaddr, uint16_t state,
}
if (ip) {
/* can get overridden by dhcp lease entry */
memcpy(&e->ipv4, ip, sizeof(*ip));
list_for_each_entry(ipaddr, &e->iplist, list) {
if (ipaddr_equal(&ipaddr->ip, ip))
ipknown = true;
......@@ -908,6 +911,9 @@ struct neigh_entry *neigh_enqueue(void *nq, uint8_t *macaddr, uint16_t state,
}
if (ip) {
/* can get overridden by dhcp lease entry */
memcpy(&e->ipv4, ip, sizeof(*ip));
list_for_each_entry(ipaddr, &e->iplist, list) {
if (ipaddr_equal(&ipaddr->ip, ip))
ipknown = true;
......
......@@ -63,6 +63,7 @@ struct neigh_entry {
void *cookie;
char hostname[256];
struct ip_address ipv4; /* from dhcp-lease table or neigh cache */
int ipv4_type_dhcp; /* set 1 when dhcp assigned ipv4 address */
unsigned long leasetime; /* lease time() end if dhcp addresses */
struct list_head iplist; /* list of struct ip_address_entry */
struct hlist_node hlist;
......
......@@ -359,7 +359,7 @@ int topologyd_ubus_show_hosts(struct ubus_context *ctx, struct ubus_object *obj,
hlist_for_each_entry(e, &q->table[i], hlist) {
struct ip_address_entry *ipv4, *ipv6;
unsigned long leasetime_rem;
long leasetime_rem;
char statestr[128] = {0};
char ip4buf[32] = {0};
char *ifname = NULL;
......@@ -378,7 +378,11 @@ int topologyd_ubus_show_hosts(struct ubus_context *ctx, struct ubus_object *obj,
inet_ntop(e->ipv4.family, &e->ipv4.addr, ip4buf, sizeof(ip4buf));
blobmsg_add_string(&bb, "ipv4addr", ip4buf);
leasetime_rem = e->leasetime ? e->leasetime - (unsigned long)time(NULL) : 0;
blobmsg_add_string(&bb, "address_source", leasetime_rem ? "DHCP": "Static");
if (leasetime_rem < 0) {
leasetime_rem = 0;
topology_get_neigh_hostname(q, e->macaddr); //TODO: move to inotify cb
}
blobmsg_add_string(&bb, "address_source", e->ipv4_type_dhcp ? "DHCP": "Static");
blobmsg_add_u32(&bb, "lease_time_remaining", leasetime_rem);
blobmsg_add_u8(&bb, "iswifi", e->type == NEIGH_TYPE_WIFI ? true : false);
blobmsg_add_u8(&bb, "is1905", e->is1905 ? true : false);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment