X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=netlink.c;h=e41445cb47c147929e6c3f6f84e7a6691fa03144;hb=794f2398b8fe84bf398bb10d6eeca6fe6737f65f;hp=886ce058cd6099c4a9d3a2bc7af16f6b9a5bde9e;hpb=9d3a4132788b198345116624761c12ed7bc936b6;p=secnet.git diff --git a/netlink.c b/netlink.c index 886ce05..e41445c 100644 --- a/netlink.c +++ b/netlink.c @@ -10,7 +10,12 @@ #include "secnet.h" #include "util.h" +#include "ipaddr.h" #include "netlink.h" +#include "process.h" + +#define OPT_SOFTROUTE 1 +#define OPT_ALLOWROUTE 2 /* Generic IP checksum routine */ static inline uint16_t ip_csum(uint8_t *iph,uint32_t count) @@ -175,11 +180,19 @@ static void netlink_icmp_csum(struct icmphdr *h) static bool_t netlink_icmp_may_reply(struct buffer_if *buf) { struct iphdr *iph; + struct icmphdr *icmph; uint32_t source; iph=(struct iphdr *)buf->start; - if (iph->protocol==1) return False; /* Overly-broad; we may reply to - eg. icmp echo-request */ + icmph=(struct icmphdr *)buf->start; + if (iph->protocol==1) { + switch(icmph->type) { + case 3: /* Destination unreachable */ + case 11: /* Time Exceeded */ + case 12: /* Parameter Problem */ + return False; + } + } /* How do we spot broadcast destination addresses? */ if (ntohs(iph->frag_off)&0x1fff) return False; /* Non-initial fragment */ source=ntohl(iph->saddr); @@ -252,9 +265,8 @@ static bool_t netlink_check(struct netlink *st, struct buffer_if *buf) return True; } -/* Deliver a packet. "client" points to the _origin_ of the packet, not - its destination. (May be used when sending ICMP response - avoid - asymmetric routing.) */ +/* Deliver a packet. "client" is the _origin_ of the packet, not its +destination. */ static void netlink_packet_deliver(struct netlink *st, struct netlink_client *client, struct buffer_if *buf) @@ -263,75 +275,105 @@ static void netlink_packet_deliver(struct netlink *st, uint32_t dest=ntohl(iph->daddr); uint32_t source=ntohl(iph->saddr); uint32_t best_quality; + bool_t allow_route=False; + bool_t found_allowed=False; int best_match; int i; BUF_ASSERT_USED(buf); if (dest==st->secnet_address) { - Message(M_ERROR,"%s: trying to deliver a packet to myself!\n"); + Message(M_ERR,"%s: trying to deliver a packet to myself!\n"); BUF_FREE(buf); return; } - if (!client) { - /* Origin of packet is host or secnet. Might be for a tunnel. */ - best_quality=0; - best_match=-1; - for (i=0; in_routes; i++) { - if (st->routes[i].up && subnet_match(&st->routes[i].net,dest)) { - if (st->routes[i].c->link_quality>best_quality - || best_quality==0) { - best_quality=st->routes[i].c->link_quality; - best_match=i; - /* If quality isn't perfect we may wish to - consider kicking the tunnel with a 0-length - packet to prompt it to perform a key setup. - Then it'll eventually decide it's up or - down. */ - /* If quality is perfect we don't need to search - any more. */ - if (best_quality>=MAXIMUM_LINK_QUALITY) break; - } - } - } - if (best_match==-1) { - /* Not going down a tunnel. Might be for the host. - XXX think about this - only situation should be if we're - sending ICMP. */ - if (source!=st->secnet_address) { - Message(M_ERROR,"netlink_packet_deliver: outgoing packet " - "from host that won't fit down any of our tunnels!\n"); - /* XXX I think this could also occur if a soft tunnel just - went down, but still had packets queued in the kernel. */ - BUF_FREE(buf); - } else { - st->deliver_to_host(st->dst,NULL,buf); - BUF_ASSERT_FREE(buf); + /* Packets from the host (client==NULL) will always be routed. Packets + from clients with the allow_route option will also be routed. */ + if (!client || (client && (client->options & OPT_ALLOWROUTE))) + allow_route=True; + + /* If !allow_route, we check the routing table anyway, and if + there's a suitable route with OPT_ALLOWROUTE set we use it. If + there's a suitable route, but none with OPT_ALLOWROUTE set then + we generate ICMP 'communication with destination network + administratively prohibited'. */ + + best_quality=0; + best_match=-1; + for (i=0; in_routes; i++) { + if (st->routes[i].up && subnet_match(st->routes[i].net,dest)) { + /* It's an available route to the correct destination. But is + it better than the one we already have? */ + + /* If we have already found an allowed route then we don't + bother looking at routes we're not allowed to use. If + we don't yet have an allowed route we'll consider any. */ + if (!allow_route && found_allowed) { + if (!(st->routes[i].c->options&OPT_ALLOWROUTE)) continue; } - } else { - if (best_quality>0) { - st->routes[best_match].c->deliver( - st->routes[best_match].c->dst, - st->routes[best_match].c, buf); - BUF_ASSERT_FREE(buf); - } else { - /* Generate ICMP destination unreachable */ - netlink_icmp_simple(st,buf,client,3,0); /* client==NULL */ - BUF_FREE(buf); + + if (st->routes[i].c->link_quality>best_quality + || best_quality==0) { + best_quality=st->routes[i].c->link_quality; + best_match=i; + if (st->routes[i].c->options&OPT_ALLOWROUTE) + found_allowed=True; + /* If quality isn't perfect we may wish to + consider kicking the tunnel with a 0-length + packet to prompt it to perform a key setup. + Then it'll eventually decide it's up or + down. */ + /* If quality is perfect and we're allowed to use the + route we don't need to search any more. */ + if (best_quality>=MAXIMUM_LINK_QUALITY && + (allow_route || found_allowed)) break; } } - } else { /* client is set */ - /* We know the origin is a tunnel - packet must be for the host */ - if (subnet_matches_list(&st->networks,dest)) { - st->deliver_to_host(st->dst,NULL,buf); + } + if (best_match==-1) { + /* The packet's not going down a tunnel. It might (ought to) + be for the host. */ + if (ipset_contains_addr(st->networks,dest)) { + st->deliver_to_host(st->dst,buf); + st->outcount++; BUF_ASSERT_FREE(buf); } else { - Message(M_ERROR,"%s: packet from tunnel %s can't be delivered " - "to the host\n",st->name,client->name); + string_t s,d; + s=ipaddr_to_string(source); + d=ipaddr_to_string(dest); + Message(M_ERR,"%s: don't know where to deliver packet " + "(s=%s, d=%s)\n", st->name, s, d); + free(s); free(d); netlink_icmp_simple(st,buf,client,3,0); BUF_FREE(buf); } + } else { + if (!allow_route && + !(st->routes[best_match].c->options&OPT_ALLOWROUTE)) { + string_t s,d; + s=ipaddr_to_string(source); + d=ipaddr_to_string(dest); + /* We have a usable route but aren't allowed to use it. + Generate ICMP destination unreachable: communication + with destination network administratively prohibited */ + Message(M_NOTICE,"%s: denied forwarding for packet (s=%s, d=%s)\n", + st->name,s,d); + free(s); free(d); + + netlink_icmp_simple(st,buf,client,3,9); + BUF_FREE(buf); + } + if (best_quality>0) { + st->routes[best_match].c->deliver( + st->routes[best_match].c->dst, buf); + st->routes[best_match].outcount++; + BUF_ASSERT_FREE(buf); + } else { + /* Generate ICMP destination unreachable */ + netlink_icmp_simple(st,buf,client,3,0); /* client==NULL */ + BUF_FREE(buf); + } } BUF_ASSERT_FREE(buf); } @@ -366,6 +408,8 @@ static void netlink_packet_local(struct netlink *st, { struct icmphdr *h; + st->localcount++; + h=(struct icmphdr *)buf->start; if ((ntohs(h->iph.frag_off)&0xbfff)!=0) { @@ -403,10 +447,9 @@ static void netlink_packet_local(struct netlink *st, /* If cid==NULL packet is from host, otherwise cid specifies which tunnel it came from. */ -static void netlink_incoming(void *sst, void *cid, struct buffer_if *buf) +static void netlink_incoming(struct netlink *st, struct netlink_client *client, + struct buffer_if *buf) { - struct netlink *st=sst; - struct netlink_client *client=cid; uint32_t source,dest; struct iphdr *iph; @@ -423,10 +466,12 @@ static void netlink_incoming(void *sst, void *cid, struct buffer_if *buf) dest=ntohl(iph->daddr); /* Check source */ + /* XXX consider generating ICMP if we're not point-to-point and we + don't like the packet */ if (client) { - /* Check that the packet source is in 'nets' and its destination is - in st->networks */ - if (!subnet_matches_list(client->networks,source)) { + /* Check that the packet source is appropriate for the tunnel + it came down */ + if (!ipset_contains_addr(client->networks,source)) { string_t s,d; s=ipaddr_to_string(source); d=ipaddr_to_string(dest); @@ -437,7 +482,10 @@ static void netlink_incoming(void *sst, void *cid, struct buffer_if *buf) return; } } else { - if (!subnet_matches_list(&st->networks,source)) { + /* Check that the packet originates in our configured local + network, and hasn't been forwarded from elsewhere or + generated with the wrong source address */ + if (!ipset_contains_addr(st->networks,source)) { string_t s,d; s=ipaddr_to_string(source); d=ipaddr_to_string(dest); @@ -448,6 +496,22 @@ static void netlink_incoming(void *sst, void *cid, struct buffer_if *buf) return; } } + + /* If this is a point-to-point device we don't examine the + destination address at all; we blindly send it down our + one-and-only registered tunnel, or to the host, depending on + where it came from. */ + /* XXX I think we should check destination addresses */ + if (st->ptp) { + if (client) { + st->deliver_to_host(st->dst,buf); + } else { + st->clients->deliver(st->clients->dst,buf); + } + BUF_ASSERT_FREE(buf); + return; + } + /* (st->secnet_address needs checking before matching destination addresses) */ if (dest==st->secnet_address) { @@ -455,131 +519,97 @@ static void netlink_incoming(void *sst, void *cid, struct buffer_if *buf) BUF_ASSERT_FREE(buf); return; } - if (client) { - if (!subnet_matches_list(&st->networks,dest)) { - string_t s,d; - s=ipaddr_to_string(source); - d=ipaddr_to_string(dest); - Message(M_WARNING,"%s: incoming packet from tunnel %s " - "with bad destination address " - "(s=%s,d=%s)\n",st->name,client->name,s,d); - free(s); free(d); - BUF_FREE(buf); - return; - } - } netlink_packet_forward(st,client,buf); BUF_ASSERT_FREE(buf); } +static void netlink_inst_incoming(void *sst, struct buffer_if *buf) +{ + struct netlink_client *c=sst; + struct netlink *st=c->nst; + + netlink_incoming(st,c,buf); +} + +static void netlink_dev_incoming(void *sst, struct buffer_if *buf) +{ + struct netlink *st=sst; + + netlink_incoming(st,NULL,buf); +} + static void netlink_set_softlinks(struct netlink *st, struct netlink_client *c, - bool_t up) + bool_t up, uint32_t quality) { uint32_t i; if (!st->routes) return; /* Table has not yet been created */ for (i=0; in_routes; i++) { - if (!st->routes[i].hard && st->routes[i].c==c) { - st->routes[i].up=up; - st->set_route(st->dst,&st->routes[i]); + if (st->routes[i].c==c) { + st->routes[i].quality=quality; + if (!st->routes[i].hard) { + st->routes[i].up=up; + st->set_route(st->dst,&st->routes[i]); + } } } } -static void netlink_set_quality(void *sst, void *cid, uint32_t quality) +static void netlink_set_quality(void *sst, uint32_t quality) { - struct netlink *st=sst; - struct netlink_client *c=cid; + struct netlink_client *c=sst; + struct netlink *st=c->nst; c->link_quality=quality; if (c->link_quality==LINK_QUALITY_DOWN) { - netlink_set_softlinks(st,c,False); + netlink_set_softlinks(st,c,False,c->link_quality); } else { - netlink_set_softlinks(st,c,True); + netlink_set_softlinks(st,c,True,c->link_quality); } } -static void *netlink_regnets(void *sst, struct subnet_list *nets, - netlink_deliver_fn *deliver, void *dst, - uint32_t max_start_pad, uint32_t max_end_pad, - bool_t hard_routes, string_t client_name) -{ - struct netlink *st=sst; - struct netlink_client *c; - - Message(M_DEBUG_CONFIG,"netlink_regnets: request for %d networks, " - "max_start_pad=%d, max_end_pad=%d\n", - nets->entries,max_start_pad,max_end_pad); - - if (!hard_routes && !st->set_route) { - Message(M_ERROR,"%s: this netlink device does not support " - "soft routes.\n"); - return NULL; - } - - if (!hard_routes) { - /* XXX for now we assume that soft routes require root privilege; - this may not always be true. */ - require_root_privileges=True; - require_root_privileges_explanation="netlink: soft routes"; - } - -#if 0 - /* XXX POLICY: do we check nets against local networks? If we do, - that prevents things like laptop tunnels working. Perhaps we - can have a configuration option for this. Or, if the admin - really doesn't want remote sites to be able to claim local - addresses, he can list them in exclude-remote-networks. */ - if (subnet_lists_intersect(&st->networks,nets)) { - Message(M_ERROR,"%s: site %s specifies networks that " - "intersect with our local networks\n",st->name,client_name); - return False; - } -#endif /* 0 */ - /* Check that nets do not intersect st->exclude_remote_networks; - refuse to register if they do. */ - if (subnet_lists_intersect(&st->exclude_remote_networks,nets)) { - Message(M_ERROR,"%s: site %s specifies networks that " - "intersect with the explicitly excluded remote networks\n", - st->name,client_name); - return False; - } - - c=safe_malloc(sizeof(*c),"netlink_regnets"); - c->networks=nets; - c->deliver=deliver; - c->dst=dst; - c->name=client_name; /* XXX copy it? */ - c->hard_routes=hard_routes; - c->link_quality=LINK_QUALITY_DOWN; - c->next=st->clients; - st->clients=c; - if (max_start_pad > st->max_start_pad) st->max_start_pad=max_start_pad; - if (max_end_pad > st->max_end_pad) st->max_end_pad=max_end_pad; - st->n_routes+=nets->entries; - - return c; -} - -static void netlink_dump_routes(struct netlink *st) +static void netlink_dump_routes(struct netlink *st, bool_t requested) { int i; string_t net; + uint32_t c=M_INFO; - Message(M_INFO,"%s: routing table:\n",st->name); - for (i=0; in_routes; i++) { - net=subnet_to_string(&st->routes[i].net); - Message(M_INFO,"%s -> tunnel %s (%s,%s)\n",net,st->routes[i].c->name, - st->routes[i].hard?"hard":"soft", - st->routes[i].up?"up":"down"); + if (requested) c=M_WARNING; + if (st->ptp) { + net=ipaddr_to_string(st->secnet_address); + Message(c,"%s: point-to-point (remote end is %s); routes:\n", + st->name, net); free(net); - } - Message(M_INFO,"%s/32 -> netlink \"%s\"\n", - ipaddr_to_string(st->secnet_address),st->name); - for (i=0; inetworks.entries; i++) { - net=subnet_to_string(&st->networks.list[i]); - Message(M_INFO,"%s -> host\n",net); + for (i=0; in_routes; i++) { + net=subnet_to_string(st->routes[i].net); + Message(c,"%s ",net); + free(net); + } + Message(c,"\n"); + } else { + Message(c,"%s: routing table:\n",st->name); + for (i=0; in_routes; i++) { + net=subnet_to_string(st->routes[i].net); + Message(c,"%s -> tunnel %s (%s,%s route,%s,quality %d,use %d)\n",net, + st->routes[i].c->name, + st->routes[i].hard?"hard":"soft", + st->routes[i].allow_route?"free":"restricted", + st->routes[i].up?"up":"down", + st->routes[i].quality, + st->routes[i].outcount); + free(net); + } + net=ipaddr_to_string(st->secnet_address); + Message(c,"%s/32 -> netlink \"%s\" (use %d)\n", + net,st->name,st->localcount); free(net); + for (i=0; isubnets->entries; i++) { + net=subnet_to_string(st->subnets->list[i]); + Message(c,"%s ",net); + free(net); + } + if (i>0) + Message(c,"-> host (use %d)\n",st->outcount); } } @@ -607,13 +637,21 @@ static void netlink_phase_hook(void *sst, uint32_t new_phase) /* Fill the table */ i=0; for (c=st->clients; c; c=c->next) { - for (j=0; jnetworks->entries; j++) { - st->routes[i].net=c->networks->list[j]; + for (j=0; jsubnets->entries; j++) { + st->routes[i].net=c->subnets->list[j]; st->routes[i].c=c; - st->routes[i].up=c->hard_routes; /* Hard routes are always up; - soft routes default to down */ + /* Hard routes are always up; + soft routes default to down; routes with no 'deliver' function + default to down */ + st->routes[i].up=c->deliver? + (c->options&OPT_SOFTROUTE?False:True): + False; st->routes[i].kup=False; - st->routes[i].hard=c->hard_routes; + st->routes[i].hard=c->options&OPT_SOFTROUTE?False:True; + st->routes[i].allow_route=c->options&OPT_ALLOWROUTE? + True:False; + st->routes[i].quality=c->link_quality; + st->routes[i].outcount=0; i++; } } @@ -626,7 +664,148 @@ static void netlink_phase_hook(void *sst, uint32_t new_phase) qsort(st->routes,st->n_routes,sizeof(*st->routes), netlink_compare_route_specificity); - netlink_dump_routes(st); + netlink_dump_routes(st,False); +} + +static void netlink_signal_handler(void *sst, int signum) +{ + struct netlink *st=sst; + Message(M_INFO,"%s: route dump requested by SIGUSR1\n",st->name); + netlink_dump_routes(st,True); +} + +static void netlink_inst_output_config(void *sst, struct buffer_if *buf) +{ +/* struct netlink_client *c=sst; */ +/* struct netlink *st=c->nst; */ + + /* For now we don't output anything */ + BUF_ASSERT_USED(buf); +} + +static bool_t netlink_inst_check_config(void *sst, struct buffer_if *buf) +{ +/* struct netlink_client *c=sst; */ +/* struct netlink *st=c->nst; */ + + BUF_ASSERT_USED(buf); + /* We need to eat all of the configuration information from the buffer + for backward compatibility. */ + buf->size=0; + return True; +} + +static void netlink_inst_reg(void *sst, netlink_deliver_fn *deliver, + void *dst, uint32_t max_start_pad, + uint32_t max_end_pad) +{ + struct netlink_client *c=sst; + struct netlink *st=c->nst; + + if (max_start_pad > st->max_start_pad) st->max_start_pad=max_start_pad; + if (max_end_pad > st->max_end_pad) st->max_end_pad=max_end_pad; + c->deliver=deliver; + c->dst=dst; +} + +static struct flagstr netlink_option_table[]={ + { "soft", OPT_SOFTROUTE }, + { "allow-route", OPT_ALLOWROUTE }, + { NULL, 0} +}; +/* This is the routine that gets called when the closure that's + returned by an invocation of a netlink device closure (eg. tun, + userv-ipif) is invoked. It's used to create routes and pass in + information about them; the closure it returns is used by site + code. */ +static closure_t *netlink_inst_create(struct netlink *st, + struct cloc loc, dict_t *dict) +{ + struct netlink_client *c; + string_t name; + struct ipset *networks; + uint32_t options; + list_t *l; + + name=dict_read_string(dict, "name", True, st->name, loc); + + l=dict_lookup(dict,"routes"); + if (!l) + cfgfatal(loc,st->name,"required parameter \"routes\" not found\n"); + networks=string_list_to_ipset(l,loc,st->name,"routes"); + options=string_list_to_word(dict_lookup(dict,"options"), + netlink_option_table,st->name); + + if ((options&OPT_SOFTROUTE) && !st->set_route) { + cfgfatal(loc,st->name,"this netlink device does not support " + "soft routes.\n"); + return NULL; + } + + if (options&OPT_SOFTROUTE) { + /* XXX for now we assume that soft routes require root privilege; + this may not always be true. The device driver can tell us. */ + require_root_privileges=True; + require_root_privileges_explanation="netlink: soft routes"; + if (st->ptp) { + cfgfatal(loc,st->name,"point-to-point netlinks do not support " + "soft routes.\n"); + return NULL; + } + } + + /* Check that nets are a subset of st->remote_networks; + refuse to register if they are not. */ + if (!ipset_is_subset(st->remote_networks,networks)) { + cfgfatal(loc,st->name,"routes are not allowed\n"); + return NULL; + } + + c=safe_malloc(sizeof(*c),"netlink_inst_create"); + c->cl.description=name; + c->cl.type=CL_NETLINK; + c->cl.apply=NULL; + c->cl.interface=&c->ops; + c->ops.st=c; + c->ops.reg=netlink_inst_reg; + c->ops.deliver=netlink_inst_incoming; + c->ops.set_quality=netlink_set_quality; + c->ops.output_config=netlink_inst_output_config; + c->ops.check_config=netlink_inst_check_config; + c->nst=st; + + c->networks=networks; + c->subnets=ipset_to_subnet_list(networks); + c->deliver=NULL; + c->dst=NULL; + c->name=name; + c->options=options; + c->link_quality=LINK_QUALITY_DOWN; + c->next=st->clients; + st->clients=c; + st->n_routes+=c->subnets->entries; + + return &c->cl; +} + +static list_t *netlink_inst_apply(closure_t *self, struct cloc loc, + dict_t *context, list_t *args) +{ + struct netlink *st=self->interface; + + dict_t *dict; + item_t *item; + closure_t *cl; + + item=list_elem(args,0); + if (!item || item->type!=t_dict) { + cfgfatal(loc,st->name,"must have a dictionary argument\n"); + } + dict=item->data.dict; + + cl=netlink_inst_create(st,loc,dict); + + return new_closure(cl); } netlink_deliver_fn *netlink_init(struct netlink *st, @@ -635,42 +814,82 @@ netlink_deliver_fn *netlink_init(struct netlink *st, netlink_route_fn *set_route, netlink_deliver_fn *to_host) { + item_t *sa, *ptpa; + list_t *l; + st->dst=dst; st->cl.description=description; - st->cl.type=CL_NETLINK; - st->cl.apply=NULL; - st->cl.interface=&st->ops; - st->ops.st=st; - st->ops.regnets=netlink_regnets; - st->ops.deliver=netlink_incoming; - st->ops.set_quality=netlink_set_quality; + st->cl.type=CL_PURE; + st->cl.apply=netlink_inst_apply; + st->cl.interface=st; st->max_start_pad=0; st->max_end_pad=0; st->clients=NULL; st->set_route=set_route; st->deliver_to_host=to_host; - st->name=dict_read_string(dict,"name",False,"netlink",loc); + st->name=dict_read_string(dict,"name",False,description,loc); if (!st->name) st->name=description; - dict_read_subnet_list(dict, "networks", True, "netlink", loc, - &st->networks); - dict_read_subnet_list(dict, "exclude-remote-networks", False, "netlink", - loc, &st->exclude_remote_networks); - /* local-address and secnet-address do not have to be in local-networks; - however, they should be advertised in the 'sites' file for the - local site. */ - st->local_address=string_to_ipaddr( - dict_find_item(dict,"local-address", True, "netlink", loc),"netlink"); - st->secnet_address=string_to_ipaddr( - dict_find_item(dict,"secnet-address", True, "netlink", loc),"netlink"); + l=dict_lookup(dict,"networks"); + if (l) + st->networks=string_list_to_ipset(l,loc,st->name,"networks"); + else { + Message(M_WARNING,"%s: no local networks (parameter \"networks\") " + "defined\n",st->name); + st->networks=ipset_new(); + } + l=dict_lookup(dict,"remote-networks"); + if (l) { + st->remote_networks=string_list_to_ipset(l,loc,st->name, + "remote-networks"); + } else { + struct ipset *empty; + empty=ipset_new(); + st->remote_networks=ipset_complement(empty); + ipset_free(empty); + } + + sa=dict_find_item(dict,"secnet-address",False,"netlink",loc); + ptpa=dict_find_item(dict,"ptp-address",False,"netlink",loc); + if (sa && ptpa) { + cfgfatal(loc,st->name,"you may not specify secnet-address and " + "ptp-address in the same netlink device\n"); + } + if (!(sa || ptpa)) { + cfgfatal(loc,st->name,"you must specify secnet-address or " + "ptp-address for this netlink device\n"); + } + if (sa) { + st->secnet_address=string_item_to_ipaddr(sa,"netlink"); + st->ptp=False; + } else { + st->secnet_address=string_item_to_ipaddr(ptpa,"netlink"); + st->ptp=True; + } + /* XXX we may want to subtract secnet_address from networks here, to + be strictly correct. It shouldn't make any practical difference, + though, and will make the route dump look complicated... */ + st->subnets=ipset_to_subnet_list(st->networks); st->mtu=dict_read_number(dict, "mtu", False, "netlink", loc, DEFAULT_MTU); buffer_new(&st->icmp,ICMP_BUFSIZE); st->n_routes=0; st->routes=NULL; + st->outcount=0; + st->localcount=0; add_hook(PHASE_SETUP,netlink_phase_hook,st); - - return netlink_incoming; + request_signal_notification(SIGUSR1, netlink_signal_handler, st); + + /* If we're point-to-point then we return a CL_NETLINK directly, + rather than a CL_NETLINK_OLD or pure closure (depending on + compatibility). This CL_NETLINK is for our one and only + client. Our cl.apply function is NULL. */ + if (st->ptp) { + closure_t *cl; + cl=netlink_inst_create(st,loc,dict); + st->cl=*cl; + } + return netlink_dev_incoming; } /* No connection to the kernel at all... */ @@ -685,7 +904,7 @@ static bool_t null_set_route(void *sst, struct netlink_route *route) string_t t; if (route->up!=route->kup) { - t=subnet_to_string(&route->net); + t=subnet_to_string(route->net); Message(M_INFO,"%s: setting route %s to state %s\n",st->nl.name, t, route->up?"up":"down"); free(t); @@ -695,7 +914,7 @@ static bool_t null_set_route(void *sst, struct netlink_route *route) return False; } -static void null_deliver(void *sst, void *cid, struct buffer_if *buf) +static void null_deliver(void *sst, struct buffer_if *buf) { return; }