summaryrefslogtreecommitdiff
path: root/sysdep
diff options
context:
space:
mode:
authorJan Moskyto Matejka <mq@ucw.cz>2016-05-10 14:30:49 +0200
committerJan Moskyto Matejka <mq@ucw.cz>2016-05-10 14:30:49 +0200
commit0c6dfe52369a59d7f3da8ee6bc7c505e3da5c064 (patch)
tree264aa0aa4e9393491d74d473181faab4ae288cb9 /sysdep
parent7a7ac656829223713f9e6bcef63d2b5a5efce7d2 (diff)
parent92912f063a94bd7c743a25628ca2073380e09ef4 (diff)
Merge branch 'int-new' into int-new-merged
Diffstat (limited to 'sysdep')
-rw-r--r--sysdep/bsd/Makefile5
-rw-r--r--sysdep/bsd/Modules4
-rw-r--r--sysdep/bsd/krt-sock.c6
-rw-r--r--sysdep/cf/bsd.h3
-rw-r--r--sysdep/cf/linux.h5
-rw-r--r--sysdep/linux/Makefile4
-rw-r--r--sysdep/linux/Modules5
-rw-r--r--sysdep/linux/netlink.c72
-rw-r--r--sysdep/unix/Makefile5
-rw-r--r--sysdep/unix/Modules12
-rw-r--r--sysdep/unix/config.Y2
-rw-r--r--sysdep/unix/io.c6
-rw-r--r--sysdep/unix/krt.Y2
-rw-r--r--sysdep/unix/krt.c9
-rw-r--r--sysdep/unix/krt.h5
-rw-r--r--sysdep/unix/log.c2
-rw-r--r--sysdep/unix/main.c6
-rw-r--r--sysdep/unix/unix.h6
18 files changed, 84 insertions, 75 deletions
diff --git a/sysdep/bsd/Makefile b/sysdep/bsd/Makefile
new file mode 100644
index 00000000..ddc87239
--- /dev/null
+++ b/sysdep/bsd/Makefile
@@ -0,0 +1,5 @@
+src := krt-sock.c
+obj := $(src-o-files)
+$(all-daemon)
+$(conf-y-targets): $(s)krt-sock.Y
+
diff --git a/sysdep/bsd/Modules b/sysdep/bsd/Modules
deleted file mode 100644
index 96455db7..00000000
--- a/sysdep/bsd/Modules
+++ /dev/null
@@ -1,4 +0,0 @@
-krt-sock.c
-krt-sock.Y
-krt-sys.h
-sysio.h
diff --git a/sysdep/bsd/krt-sock.c b/sysdep/bsd/krt-sock.c
index 9f84b3f5..56026bdd 100644
--- a/sysdep/bsd/krt-sock.c
+++ b/sysdep/bsd/krt-sock.c
@@ -28,9 +28,9 @@
#include "nest/route.h"
#include "nest/protocol.h"
#include "nest/iface.h"
-#include "lib/timer.h"
-#include "lib/unix.h"
-#include "lib/krt.h"
+#include "sysdep/unix/timer.h"
+#include "sysdep/unix/unix.h"
+#include "sysdep/unix/krt.h"
#include "lib/string.h"
#include "lib/socket.h"
diff --git a/sysdep/cf/bsd.h b/sysdep/cf/bsd.h
index 51beb42b..22c54277 100644
--- a/sysdep/cf/bsd.h
+++ b/sysdep/cf/bsd.h
@@ -15,6 +15,9 @@
#define CONFIG_NO_IFACE_BIND
#define CONFIG_USE_HDRINCL
+#define CONFIG_INCLUDE_SYSIO_H "sysdep/bsd/sysio.h"
+#define CONFIG_INCLUDE_KRTSYS_H "sysdep/bsd/krt-sys.h"
+
/*
Link: sysdep/unix
Link: sysdep/bsd
diff --git a/sysdep/cf/linux.h b/sysdep/cf/linux.h
index 9e34f869..cec9499c 100644
--- a/sysdep/cf/linux.h
+++ b/sysdep/cf/linux.h
@@ -14,7 +14,12 @@
#define CONFIG_MC_PROPER_SRC
#define CONFIG_UNIX_DONTROUTE
+#define CONFIG_INCLUDE_SYSIO_H "sysdep/linux/sysio.h"
+#define CONFIG_INCLUDE_KRTSYS_H "sysdep/linux/krt-sys.h"
+
#define CONFIG_RESTRICTED_PRIVILEGES
+#define CONFIG_INCLUDE_SYSPRIV_H "sysdep/linux/syspriv.h"
+
/*
Link: sysdep/linux
diff --git a/sysdep/linux/Makefile b/sysdep/linux/Makefile
new file mode 100644
index 00000000..23cf1d9d
--- /dev/null
+++ b/sysdep/linux/Makefile
@@ -0,0 +1,4 @@
+src := netlink.c
+obj := $(src-o-files)
+$(all-daemon)
+$(conf-y-targets): $(s)netlink.Y
diff --git a/sysdep/linux/Modules b/sysdep/linux/Modules
deleted file mode 100644
index 940660b6..00000000
--- a/sysdep/linux/Modules
+++ /dev/null
@@ -1,5 +0,0 @@
-krt-sys.h
-netlink.c
-netlink.Y
-sysio.h
-syspriv.h
diff --git a/sysdep/linux/netlink.c b/sysdep/linux/netlink.c
index c398a7f6..8166d5f5 100644
--- a/sysdep/linux/netlink.c
+++ b/sysdep/linux/netlink.c
@@ -6,6 +6,7 @@
* Can be freely distributed and used under the terms of the GNU GPL.
*/
+#include <alloca.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
@@ -20,9 +21,9 @@
#include "nest/protocol.h"
#include "nest/iface.h"
#include "lib/alloca.h"
-#include "lib/timer.h"
-#include "lib/unix.h"
-#include "lib/krt.h"
+#include "sysdep/unix/timer.h"
+#include "sysdep/unix/unix.h"
+#include "sysdep/unix/krt.h"
#include "lib/socket.h"
#include "lib/string.h"
#include "lib/hash.h"
@@ -915,44 +916,49 @@ nl_send_route(struct krt_proto *p, rte *e, struct ea_list *eattrs, int new)
eattr *ea;
net *net = e->net;
rta *a = e->attrs;
+ int bufsize = 128 + KRT_METRICS_MAX*8 + nh_bufsize(a->nexthops);
+
struct {
struct nlmsghdr h;
struct rtmsg r;
- char buf[128 + KRT_METRICS_MAX*8 + nh_bufsize(a->nexthops)];
- } r;
+ char buf[0];
+ } *r;
+
+ int rsize = sizeof(*r) + bufsize;
+ r = alloca(rsize);
DBG("nl_send_route(%N,new=%d)\n", net->n.addr, new);
- bzero(&r.h, sizeof(r.h));
- bzero(&r.r, sizeof(r.r));
- r.h.nlmsg_type = new ? RTM_NEWROUTE : RTM_DELROUTE;
- r.h.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
- r.h.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | (new ? NLM_F_CREATE|NLM_F_EXCL : 0);
+ bzero(&r->h, sizeof(r->h));
+ bzero(&r->r, sizeof(r->r));
+ r->h.nlmsg_type = new ? RTM_NEWROUTE : RTM_DELROUTE;
+ r->h.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
+ r->h.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | (new ? NLM_F_CREATE|NLM_F_EXCL : 0);
- r.r.rtm_family = p->af;
- r.r.rtm_dst_len = net_pxlen(net->n.addr);
- r.r.rtm_protocol = RTPROT_BIRD;
- r.r.rtm_scope = RT_SCOPE_UNIVERSE;
- nl_add_attr_ipa(&r.h, sizeof(r), RTA_DST, net_prefix(net->n.addr));
+ r->r.rtm_family = p->af;
+ r->r.rtm_dst_len = net_pxlen(net->n.addr);
+ r->r.rtm_protocol = RTPROT_BIRD;
+ r->r.rtm_scope = RT_SCOPE_UNIVERSE;
+ nl_add_attr_ipa(&r->h, rsize, RTA_DST, net_prefix(net->n.addr));
if (krt_table_id(p) < 256)
- r.r.rtm_table = krt_table_id(p);
+ r->r.rtm_table = krt_table_id(p);
else
- nl_add_attr_u32(&r.h, sizeof(r), RTA_TABLE, krt_table_id(p));
+ nl_add_attr_u32(&r->h, rsize, RTA_TABLE, krt_table_id(p));
/* For route delete, we do not specify route attributes */
if (!new)
- return nl_exchange(&r.h);
+ return nl_exchange(&r->h);
if (ea = ea_find(eattrs, EA_KRT_METRIC))
- nl_add_attr_u32(&r.h, sizeof(r), RTA_PRIORITY, ea->u.data);
+ nl_add_attr_u32(&r->h, rsize, RTA_PRIORITY, ea->u.data);
if (ea = ea_find(eattrs, EA_KRT_PREFSRC))
- nl_add_attr_ipa(&r.h, sizeof(r), RTA_PREFSRC, *(ip_addr *)ea->u.ptr->data);
+ nl_add_attr_ipa(&r->h, rsize, RTA_PREFSRC, *(ip_addr *)ea->u.ptr->data);
if (ea = ea_find(eattrs, EA_KRT_REALM))
- nl_add_attr_u32(&r.h, sizeof(r), RTA_FLOW, ea->u.data);
+ nl_add_attr_u32(&r->h, rsize, RTA_FLOW, ea->u.data);
u32 metrics[KRT_METRICS_MAX];
@@ -967,7 +973,7 @@ nl_send_route(struct krt_proto *p, rte *e, struct ea_list *eattrs, int new)
}
if (metrics[0])
- nl_add_metrics(&r.h, sizeof(r), metrics, KRT_METRICS_MAX);
+ nl_add_metrics(&r->h, rsize, metrics, KRT_METRICS_MAX);
/* a->iface != NULL checked in krt_capable() for router and device routes */
@@ -975,32 +981,32 @@ nl_send_route(struct krt_proto *p, rte *e, struct ea_list *eattrs, int new)
switch (a->dest)
{
case RTD_ROUTER:
- r.r.rtm_type = RTN_UNICAST;
- nl_add_attr_u32(&r.h, sizeof(r), RTA_OIF, a->iface->index);
- nl_add_attr_ipa(&r.h, sizeof(r), RTA_GATEWAY, a->gw);
+ r->r.rtm_type = RTN_UNICAST;
+ nl_add_attr_u32(&r->h, rsize, RTA_OIF, a->iface->index);
+ nl_add_attr_ipa(&r->h, rsize, RTA_GATEWAY, a->gw);
break;
case RTD_DEVICE:
- r.r.rtm_type = RTN_UNICAST;
- nl_add_attr_u32(&r.h, sizeof(r), RTA_OIF, a->iface->index);
+ r->r.rtm_type = RTN_UNICAST;
+ nl_add_attr_u32(&r->h, rsize, RTA_OIF, a->iface->index);
break;
case RTD_BLACKHOLE:
- r.r.rtm_type = RTN_BLACKHOLE;
+ r->r.rtm_type = RTN_BLACKHOLE;
break;
case RTD_UNREACHABLE:
- r.r.rtm_type = RTN_UNREACHABLE;
+ r->r.rtm_type = RTN_UNREACHABLE;
break;
case RTD_PROHIBIT:
- r.r.rtm_type = RTN_PROHIBIT;
+ r->r.rtm_type = RTN_PROHIBIT;
break;
case RTD_MULTIPATH:
- r.r.rtm_type = RTN_UNICAST;
- nl_add_multipath(&r.h, sizeof(r), a->nexthops);
+ r->r.rtm_type = RTN_UNICAST;
+ nl_add_multipath(&r->h, rsize, a->nexthops);
break;
default:
bug("krt_capable inconsistent with nl_send_route");
}
- return nl_exchange(&r.h);
+ return nl_exchange(&r->h);
}
void
diff --git a/sysdep/unix/Makefile b/sysdep/unix/Makefile
new file mode 100644
index 00000000..c5d55431
--- /dev/null
+++ b/sysdep/unix/Makefile
@@ -0,0 +1,5 @@
+src := io.c krt.c log.c main.c random.c
+obj := $(src-o-files)
+$(all-daemon)
+$(cf-local)
+$(conf-y-targets): $(s)krt.Y
diff --git a/sysdep/unix/Modules b/sysdep/unix/Modules
deleted file mode 100644
index 2c6514df..00000000
--- a/sysdep/unix/Modules
+++ /dev/null
@@ -1,12 +0,0 @@
-log.c
-main.c
-timer.h
-io.c
-unix.h
-endian.h
-config.Y
-random.c
-
-krt.c
-krt.h
-krt.Y
diff --git a/sysdep/unix/config.Y b/sysdep/unix/config.Y
index f9a92900..ebadd454 100644
--- a/sysdep/unix/config.Y
+++ b/sysdep/unix/config.Y
@@ -8,7 +8,7 @@
CF_HDR
-#include "lib/unix.h"
+#include "sysdep/unix/unix.h"
#include <stdio.h>
CF_DECLS
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c
index 37e26c9b..4db6abb7 100644
--- a/sysdep/unix/io.c
+++ b/sysdep/unix/io.c
@@ -32,14 +32,14 @@
#include "nest/bird.h"
#include "lib/lists.h"
#include "lib/resource.h"
-#include "lib/timer.h"
+#include "sysdep/unix/timer.h"
#include "lib/socket.h"
#include "lib/event.h"
#include "lib/string.h"
#include "nest/iface.h"
-#include "lib/unix.h"
-#include "lib/sysio.h"
+#include "sysdep/unix/unix.h"
+#include CONFIG_INCLUDE_SYSIO_H
/* Maximum number of calls of tx handler for one socket in one
* poll iteration. Should be small enough to not monopolize CPU by
diff --git a/sysdep/unix/krt.Y b/sysdep/unix/krt.Y
index 1cd73502..91317d97 100644
--- a/sysdep/unix/krt.Y
+++ b/sysdep/unix/krt.Y
@@ -8,7 +8,7 @@
CF_HDR
-#include "lib/krt.h"
+#include "sysdep/unix/krt.h"
CF_DEFINES
diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c
index b0a96613..6531bb28 100644
--- a/sysdep/unix/krt.c
+++ b/sysdep/unix/krt.c
@@ -56,7 +56,7 @@
#include "nest/route.h"
#include "nest/protocol.h"
#include "filter/filter.h"
-#include "lib/timer.h"
+#include "sysdep/unix/timer.h"
#include "conf/conf.h"
#include "lib/string.h"
@@ -345,18 +345,15 @@ krt_learn_announce_update(struct krt_proto *p, rte *e)
net *n = e->net;
rta *aa = rta_clone(e->attrs);
rte *ee = rte_get_temp(aa);
- net *nn = net_get(p->p.main_channel->table, n->n.addr);
- ee->net = nn;
ee->pflags = 0;
ee->u.krt = e->u.krt;
- rte_update(&p->p, nn, ee);
+ rte_update(&p->p, n->n.addr, ee);
}
static void
krt_learn_announce_delete(struct krt_proto *p, net *n)
{
- n = net_find(p->p.main_channel->table, n->n.addr);
- rte_update(&p->p, n, NULL);
+ rte_update(&p->p, n->n.addr, NULL);
}
/* Called when alien route is discovered during scan */
diff --git a/sysdep/unix/krt.h b/sysdep/unix/krt.h
index e968ad57..cb404de3 100644
--- a/sysdep/unix/krt.h
+++ b/sysdep/unix/krt.h
@@ -15,7 +15,8 @@ struct krt_proto;
struct kif_config;
struct kif_proto;
-#include "lib/krt-sys.h"
+#include "sysdep/config.h"
+#include CONFIG_INCLUDE_KRTSYS_H
/* Flags stored in net->n.flags, rest are in nest/route.h */
@@ -111,7 +112,7 @@ struct kif_proto {
struct kif_state sys; /* Sysdep state */
};
-struct kif_proto *kif_proto;
+extern struct kif_proto *kif_proto;
#define KIF_CF ((struct kif_config *)p->p.cf)
diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c
index b90bbbd2..43d98f7b 100644
--- a/sysdep/unix/log.c
+++ b/sysdep/unix/log.c
@@ -26,7 +26,7 @@
#include "nest/mrtdump.h"
#include "lib/string.h"
#include "lib/lists.h"
-#include "lib/unix.h"
+#include "sysdep/unix/unix.h"
static FILE *dbgf;
static list *current_log_list;
diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c
index f95bd968..691fee2d 100644
--- a/sysdep/unix/main.c
+++ b/sysdep/unix/main.c
@@ -69,7 +69,7 @@ async_dump(void)
*/
#ifdef CONFIG_RESTRICTED_PRIVILEGES
-#include "lib/syspriv.h"
+#include CONFIG_INCLUDE_SYSPRIV_H
#else
static inline void
@@ -569,6 +569,10 @@ sysdep_shutdown_done(void)
* Signals
*/
+volatile int async_config_flag;
+volatile int async_dump_flag;
+volatile int async_shutdown_flag;
+
static void
handle_sighup(int sig UNUSED)
{
diff --git a/sysdep/unix/unix.h b/sysdep/unix/unix.h
index 414b6ca4..80c99350 100644
--- a/sysdep/unix/unix.h
+++ b/sysdep/unix/unix.h
@@ -91,9 +91,9 @@ int sockaddr_read(sockaddr *sa, int af, ip_addr *a, struct iface **ifa, uint *po
#define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) + strlen ((ptr)->sun_path))
#endif
-volatile int async_config_flag;
-volatile int async_dump_flag;
-volatile int async_shutdown_flag;
+extern volatile int async_config_flag;
+extern volatile int async_dump_flag;
+extern volatile int async_shutdown_flag;
void io_init(void);
void io_loop(void);