summaryrefslogtreecommitdiff
path: root/nhrp
diff options
context:
space:
mode:
Diffstat (limited to 'nhrp')
-rw-r--r--nhrp/admin.c24
-rw-r--r--nhrp/nhrp_interface.c15
-rw-r--r--nhrp/nhrp_peer.c6
-rw-r--r--nhrp/nhrp_peer.h2
-rw-r--r--nhrp/sysdep_netlink.c5
5 files changed, 35 insertions, 17 deletions
diff --git a/nhrp/admin.c b/nhrp/admin.c
index 68a3e9e..d89fa87 100644
--- a/nhrp/admin.c
+++ b/nhrp/admin.c
@@ -54,10 +54,16 @@ static int parse_word(const char **bufptr, size_t len, char *word)
return TRUE;
}
+static void admin_raw_write(void *ctx, const void *buf, size_t len)
+{
+ struct admin_remote *rmt = (struct admin_remote *) ctx;
+
+ if (write(rmt->io.fd, buf, len) != len) {
+ }
+}
static void admin_write(void *ctx, const char *format, ...)
{
- struct admin_remote *rmt = (struct admin_remote *) ctx;
char msg[1024];
va_list ap;
size_t len;
@@ -66,8 +72,7 @@ static void admin_write(void *ctx, const char *format, ...)
len = vsnprintf(msg, sizeof(msg), format, ap);
va_end(ap);
- if (write(rmt->io.fd, msg, len) != len) {
- }
+ admin_raw_write(ctx, msg, len);
}
static void admin_free_remote(struct admin_remote *rm)
@@ -148,8 +153,8 @@ static int admin_show_peer(void *ctx, struct nhrp_peer *peer)
rel / 60, rel % 60);
}
}
-
- admin_write(ctx, "%s\n", buf);
+ i += snprintf(&buf[i], len - i, "\n");
+ admin_raw_write(ctx, buf, i);
return 0;
}
@@ -223,9 +228,9 @@ static int admin_parse_selector(void *ctx, const char *cmd,
} else if (strcmp(keyword, "local-nbma") == 0) {
if (sel->interface != NULL)
goto err_conflict;
- sel->interface = nhrp_interface_get_by_nbma(&address);
+ sel->local_nbma_address = address;
if (sel->interface == NULL)
- goto err_noiface;
+ sel->interface = nhrp_interface_get_by_nbma(&address);
} else {
admin_write(ctx,
"Status: failed\n"
@@ -406,7 +411,8 @@ static int admin_show_interface(void *ctx, struct nhrp_interface *iface)
nhrp_address_format(&iface->nat_cie.nbma_address, sizeof(tmp), tmp));
}
done:
- admin_write(ctx, "%s\n", buf);
+ i += snprintf(&buf[i], len - i, "\n");
+ admin_raw_write(ctx, buf, i);
return 0;
}
@@ -420,7 +426,7 @@ static void admin_redirect_purge(void *ctx, const char *cmd)
{
char keyword[64];
struct nhrp_address addr;
- uint8_t prefix;
+ uint8_t prefix = 0;
int count;
nhrp_address_set_type(&addr, PF_UNSPEC);
diff --git a/nhrp/nhrp_interface.c b/nhrp/nhrp_interface.c
index 32c2383..05f0e80 100644
--- a/nhrp/nhrp_interface.c
+++ b/nhrp/nhrp_interface.c
@@ -123,20 +123,23 @@ struct nhrp_interface *nhrp_interface_get_by_index(unsigned int index, int creat
struct nhrp_interface *nhrp_interface_get_by_nbma(struct nhrp_address *addr)
{
+ struct nhrp_interface *match = NULL;
struct nhrp_interface *iface;
list_for_each_entry(iface, &name_list, name_list_entry) {
if (!(iface->flags & NHRP_INTERFACE_FLAG_CONFIGURED))
continue;
- if (nhrp_address_cmp(addr, &iface->nbma_address) == 0)
- return iface;
-
- if (iface->nbma_address.type == PF_UNSPEC && !iface->link_index)
- return iface;
+ if ((nhrp_address_cmp(addr, &iface->nbma_address) == 0) ||
+ (iface->nbma_address.type == PF_UNSPEC && !iface->link_index)) {
+ /* ambiguous match - return null */
+ if (match != NULL)
+ return NULL;
+ match = iface;
+ }
}
- return NULL;
+ return match;
}
struct nhrp_interface *nhrp_interface_get_by_protocol(struct nhrp_address *addr)
diff --git a/nhrp/nhrp_peer.c b/nhrp/nhrp_peer.c
index c53d4c4..7bd1a79 100644
--- a/nhrp/nhrp_peer.c
+++ b/nhrp/nhrp_peer.c
@@ -1833,6 +1833,12 @@ int nhrp_peer_match(struct nhrp_peer *p, struct nhrp_peer_selector *sel)
p->parent != sel->parent)
return FALSE;
+ if (sel->local_nbma_address.type != PF_UNSPEC) {
+ if (nhrp_address_cmp(&p->my_nbma_address,
+ &sel->local_nbma_address) != 0)
+ return FALSE;
+ }
+
if (sel->protocol_address.type != PF_UNSPEC) {
if (sel->prefix_length == 0)
sel->prefix_length = sel->protocol_address.addr_len * 8;
diff --git a/nhrp/nhrp_peer.h b/nhrp/nhrp_peer.h
index dea8d66..1df5fa9 100644
--- a/nhrp/nhrp_peer.h
+++ b/nhrp/nhrp_peer.h
@@ -136,6 +136,8 @@ struct nhrp_peer_selector {
int prefix_length;
struct nhrp_address protocol_address;
struct nhrp_address next_hop_address;
+
+ struct nhrp_address local_nbma_address;
};
const char * const nhrp_peer_type[NHRP_PEER_TYPE_MAX];
diff --git a/nhrp/sysdep_netlink.c b/nhrp/sysdep_netlink.c
index d058a98..0dce865 100644
--- a/nhrp/sysdep_netlink.c
+++ b/nhrp/sysdep_netlink.c
@@ -461,8 +461,9 @@ static void netlink_link_new(struct nlmsghdr *msg)
if (rta[IFLA_MTU])
iface->mtu = *((unsigned*)RTA_DATA(rta[IFLA_MTU]));
- if (iface->index == 0 || (ifi->ifi_flags & ifi->ifi_change & IFF_UP)) {
- nhrp_info("Interface %s: new or configured up, mtu=%d",
+ if (((ifi->ifi_change & IFF_UP) || (iface->index == 0)) &&
+ (ifi->ifi_flags & IFF_UP)) {
+ nhrp_info("Interface %s: configured UP, mtu=%d",
ifname, iface->mtu);
nhrp_interface_run_script(iface, "interface-up");
} else {