summaryrefslogtreecommitdiffstats
path: root/sysdep
diff options
context:
space:
mode:
Diffstat (limited to 'sysdep')
-rw-r--r--sysdep/bsd/krt-sock.c27
-rw-r--r--sysdep/linux/netlink/netlink.c19
-rw-r--r--sysdep/unix/krt.h5
3 files changed, 30 insertions, 21 deletions
diff --git a/sysdep/bsd/krt-sock.c b/sysdep/bsd/krt-sock.c
index f6bc4a2..7229590 100644
--- a/sysdep/bsd/krt-sock.c
+++ b/sysdep/bsd/krt-sock.c
@@ -68,7 +68,7 @@ krt_capable(rte *e)
memcpy(p, body, (l > sizeof(*p) ? sizeof(*p) : l));\
body += l;}
-static void
+static int
krt_sock_send(int cmd, rte *e)
{
net *net = e->net;
@@ -160,7 +160,7 @@ krt_sock_send(int cmd, rte *e)
if(!i->addr) {
log(L_ERR "KRT: interface %s has no IP addess", i->name);
- return;
+ return -1;
}
fill_in_sockaddr(&gate, i->addr->ip, 0);
@@ -182,22 +182,27 @@ krt_sock_send(int cmd, rte *e)
if ((l = write(rt_sock, (char *)&msg, l)) < 0) {
log(L_ERR "KRT: Error sending route %I/%d to kernel", net->n.prefix, net->n.pxlen);
+ return -1;
}
+
+ return 0;
}
void
-krt_set_notify(struct krt_proto *p UNUSED, net *net, rte *new, rte *old)
+krt_set_notify(struct krt_proto *p UNUSED, net *n, rte *new, rte *old)
{
+ int err = 0;
+
if (old)
- {
- DBG("krt_remove_route(%I/%d)\n", net->n.prefix, net->n.pxlen);
- krt_sock_send(RTM_DELETE, old);
- }
+ krt_sock_send(RTM_DELETE, old);
+
if (new)
- {
- DBG("krt_add_route(%I/%d)\n", net->n.prefix, net->n.pxlen);
- krt_sock_send(RTM_ADD, new);
- }
+ err = krt_sock_send(RTM_ADD, new);
+
+ if (err < 0)
+ n->n.flags |= KRF_SYNC_ERROR;
+ else
+ n->n.flags &= ~KRF_SYNC_ERROR;
}
static int
diff --git a/sysdep/linux/netlink/netlink.c b/sysdep/linux/netlink/netlink.c
index 0830097..f8a5d63 100644
--- a/sysdep/linux/netlink/netlink.c
+++ b/sysdep/linux/netlink/netlink.c
@@ -198,7 +198,7 @@ nl_exchange(struct nlmsghdr *pkt)
break;
log(L_WARN "nl_exchange: Unexpected reply received");
}
- return nl_error(h);
+ return nl_error(h) ? -1 : 0;
}
/*
@@ -616,7 +616,7 @@ nh_bufsize(struct mpnh *nh)
return rv;
}
-static void
+static int
nl_send_route(struct krt_proto *p, rte *e, int new)
{
eattr *ea;
@@ -663,7 +663,7 @@ nl_send_route(struct krt_proto *p, rte *e, int new)
break;
case RTD_DEVICE:
if (!a->iface)
- return;
+ return -1;
r.r.rtm_type = RTN_UNICAST;
nl_add_attr_u32(&r.h, sizeof(r), RTA_OIF, a->iface->index);
break;
@@ -684,17 +684,24 @@ nl_send_route(struct krt_proto *p, rte *e, int new)
bug("krt_capable inconsistent with nl_send_route");
}
- nl_exchange(&r.h);
+ return nl_exchange(&r.h);
}
void
-krt_set_notify(struct krt_proto *p, net *n UNUSED, rte *new, rte *old)
+krt_set_notify(struct krt_proto *p, net *n, rte *new, rte *old)
{
+ int err = 0;
+
if (old)
nl_send_route(p, old, 0);
if (new)
- nl_send_route(p, new, 1);
+ err = nl_send_route(p, new, 1);
+
+ if (err < 0)
+ n->n.flags |= KRF_SYNC_ERROR;
+ else
+ n->n.flags &= ~KRF_SYNC_ERROR;
}
diff --git a/sysdep/unix/krt.h b/sysdep/unix/krt.h
index c88bc48..f83e6ee 100644
--- a/sysdep/unix/krt.h
+++ b/sysdep/unix/krt.h
@@ -19,7 +19,7 @@ struct kif_proto;
#include "lib/krt-set.h"
#include "lib/krt-iface.h"
-/* Flags stored in net->n.flags */
+/* Flags stored in net->n.flags, rest are in nest/route.h */
#define KRF_VERDICT_MASK 0x0f
#define KRF_CREATE 0 /* Not seen in kernel table */
@@ -28,9 +28,6 @@ struct kif_proto;
#define KRF_DELETE 3 /* Should be deleted */
#define KRF_IGNORE 4 /* To be ignored */
-#define KRF_INSTALLED 0x80 /* This route should be installed in the kernel */
-
-
#define EA_KRT_PREFSRC EA_CODE(EAP_KRT, 0)
#define EA_KRT_REALM EA_CODE(EAP_KRT, 1)