summaryrefslogtreecommitdiff
path: root/sysdep/bsd/krt-sock.c
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2012-04-30 15:31:32 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2012-04-30 15:31:32 +0200
commit396dfa9042305f62da1f56589c4b98fac57fc2f6 (patch)
treefcd1bcf1a7b1afe9a98d11018c77ecff68b40f63 /sysdep/bsd/krt-sock.c
parent182a78957d60a4c91c1ff8d1ff0f09b1b64b70ba (diff)
Cleanup in sysdep KRT code, part 1.
OS-dependent functions renamed to be more consistent, prepared to merge krt-set and krt-scan headers. Name changes: struct krt_if_params -> struct kif_params struct krt_if_status -> struct kif_status struct krt_set/scan_params -> struct krt_params struct krt_set/scan_status -> struct krt_status krt_if_params_same -> kif_sys_reconfigure krt_if_copy_params -> kif_sys_copy_config krt_set/scan_params_same -> krt_sys_reconfigure krt_set/scan_copy_params -> krt_sys_copy_config krt_if_scan -> kif_do_scan krt_set_notify -> krt_do_notify krt_scan_fire -> krt_do_scan krt_if_ -> kif_sys_ krt_scan_ -> krt_sys_ krt_set_ -> krt_sys_
Diffstat (limited to 'sysdep/bsd/krt-sock.c')
-rw-r--r--sysdep/bsd/krt-sock.c137
1 files changed, 54 insertions, 83 deletions
diff --git a/sysdep/bsd/krt-sock.c b/sysdep/bsd/krt-sock.c
index 9ca36d83..5fb5f9f7 100644
--- a/sysdep/bsd/krt-sock.c
+++ b/sysdep/bsd/krt-sock.c
@@ -33,7 +33,19 @@
#include "lib/string.h"
#include "lib/socket.h"
-int rt_sock = 0;
+
+#ifndef RTAX_MAX
+#define RTAX_MAX 8
+#endif
+
+struct ks_msg
+{
+ struct rt_msghdr rtm;
+ struct sockaddr_storage buf[RTAX_MAX];
+};
+
+
+static int rt_sock = 0;
int
krt_capable(rte *e)
@@ -189,8 +201,8 @@ krt_sock_send(int cmd, rte *e)
}
void
-krt_set_notify(struct krt_proto *p UNUSED, net *n, rte *new, rte *old,
- struct ea_list *eattrs UNUSED)
+krt_do_notify(struct krt_proto *p UNUSED, net *n, rte *new, rte *old,
+ struct ea_list *eattrs UNUSED)
{
int err = 0;
@@ -206,45 +218,6 @@ krt_set_notify(struct krt_proto *p UNUSED, net *n, rte *new, rte *old,
n->n.flags &= ~KRF_SYNC_ERROR;
}
-static int
-krt_set_hook(sock *sk, int size UNUSED)
-{
- struct ks_msg msg;
- int l = read(sk->fd, (char *)&msg, sizeof(msg));
-
- if(l <= 0)
- log(L_ERR "krt-sock: read failed");
- else
- krt_read_msg((struct proto *)sk->data, &msg, 0);
-
- return 0;
-}
-
-void
-krt_set_start(struct krt_proto *x, int first UNUSED)
-{
- sock *sk_rt;
- static int ks_open_tried = 0;
-
- if (ks_open_tried)
- return;
-
- ks_open_tried = 1;
-
- DBG("KRT: Opening kernel socket\n");
-
- if( (rt_sock = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC)) < 0)
- die("Cannot open kernel socket for routes");
-
- sk_rt = sk_new(krt_pool);
- sk_rt->type = SK_MAGIC;
- sk_rt->rx_hook = krt_set_hook;
- sk_rt->fd = rt_sock;
- sk_rt->data = x;
- if (sk_open(sk_rt))
- bug("krt-sock: sk_open failed");
-}
-
#define SKIP(ARG...) do { DBG("KRT: Ignoring route - " ARG); return; } while(0)
static void
@@ -648,32 +621,6 @@ krt_read_msg(struct proto *p, struct ks_msg *msg, int scan)
}
}
-void
-krt_scan_construct(struct krt_config *c UNUSED)
-{
-}
-
-void
-krt_scan_preconfig(struct config *c UNUSED)
-{
-}
-
-void
-krt_scan_postconfig(struct krt_config *c UNUSED)
-{
-}
-
-void
-krt_scan_start(struct krt_proto *x, int first UNUSED)
-{
- init_list(&x->scan.temp_ifs);
-}
-
-void
-krt_scan_shutdown(struct krt_proto *x UNUSED, int last UNUSED)
-{
-}
-
static void
krt_sysctl_scan(struct proto *p, pool *pool, byte **buf, size_t *bl, int cmd)
{
@@ -732,13 +679,13 @@ static size_t krt_buflen = 32768;
static size_t kif_buflen = 4096;
void
-krt_scan_fire(struct krt_proto *p)
+krt_do_scan(struct krt_proto *p)
{
krt_sysctl_scan((struct proto *)p, p->krt_pool, &krt_buffer, &krt_buflen, NET_RT_DUMP);
}
void
-krt_if_scan(struct kif_proto *p)
+kif_do_scan(struct kif_proto *p)
{
struct proto *P = (struct proto *)p;
if_start_update();
@@ -746,14 +693,47 @@ krt_if_scan(struct kif_proto *p)
if_end_update();
}
+static int
+krt_sock_hook(sock *sk, int size UNUSED)
+{
+ struct ks_msg msg;
+ int l = read(sk->fd, (char *)&msg, sizeof(msg));
+
+ if(l <= 0)
+ log(L_ERR "krt-sock: read failed");
+ else
+ krt_read_msg((struct proto *)sk->data, &msg, 0);
+
+ return 0;
+}
void
-krt_set_construct(struct krt_config *c UNUSED)
+krt_sys_start(struct krt_proto *x, int first UNUSED)
{
+ sock *sk_rt;
+ static int ks_open_tried = 0;
+
+ if (ks_open_tried)
+ return;
+
+ ks_open_tried = 1;
+
+ DBG("KRT: Opening kernel socket\n");
+
+ if( (rt_sock = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC)) < 0)
+ die("Cannot open kernel socket for routes");
+
+ sk_rt = sk_new(krt_pool);
+ sk_rt->type = SK_MAGIC;
+ sk_rt->rx_hook = krt_sock_hook;
+ sk_rt->fd = rt_sock;
+ sk_rt->data = x;
+ if (sk_open(sk_rt))
+ bug("krt-sock: sk_open failed");
}
void
-krt_set_shutdown(struct krt_proto *x UNUSED, int last UNUSED)
+krt_sys_shutdown(struct krt_proto *x UNUSED, int last UNUSED)
{
if (!krt_buffer)
return;
@@ -762,23 +742,14 @@ krt_set_shutdown(struct krt_proto *x UNUSED, int last UNUSED)
krt_buffer = NULL;
}
-void
-krt_if_io_init(void)
-{
-}
-
-void
-krt_if_construct(struct kif_config *c UNUSED)
-{
-}
void
-krt_if_start(struct kif_proto *p UNUSED)
+kif_sys_start(struct kif_proto *p UNUSED)
{
}
void
-krt_if_shutdown(struct kif_proto *p UNUSED)
+kif_sys_shutdown(struct kif_proto *p UNUSED)
{
if (!kif_buffer)
return;