X-Git-Url: https://git.distorted.org.uk/~mdw/secnet/blobdiff_plain/a6768d7c5a9c2439974f9ad97d1528467274a3fe..f928f0694ff6b90d5fc429cfe910eaba9fdd3fd0:/netlink.c diff --git a/netlink.c b/netlink.c index b8f22d3..97e1af9 100644 --- a/netlink.c +++ b/netlink.c @@ -367,7 +367,6 @@ static uint16_t netlink_icmp_reply_len(struct buffer_if *buf) /* client indicates where the packet we're constructing a response to comes from. NULL indicates the host. */ static void netlink_icmp_simple(struct netlink *st, struct buffer_if *buf, - struct netlink_client *client, uint8_t type, uint8_t code, union icmpinfofield info) { @@ -446,6 +445,16 @@ static void netlink_client_deliver(struct netlink *st, client->outcount++; } +/* Deliver a packet to the host; used after we have decided that that + * is what to do with it. */ +static void netlink_host_deliver(struct netlink *st, + uint32_t source, uint32_t dest, + struct buffer_if *buf) +{ + st->deliver_to_host(st->dst,buf); + st->outcount++; +} + /* Deliver a packet. "client" is the _origin_ of the packet, not its destination, and is NULL for packets from the host and packets generated internally in secnet. */ @@ -525,8 +534,7 @@ static void netlink_packet_deliver(struct netlink *st, /* 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++; + netlink_host_deliver(st,source,dest,buf); BUF_ASSERT_FREE(buf); } else { string_t s,d; @@ -535,7 +543,7 @@ static void netlink_packet_deliver(struct netlink *st, Message(M_DEBUG,"%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,ICMP_TYPE_UNREACHABLE, + netlink_icmp_simple(st,buf,ICMP_TYPE_UNREACHABLE, ICMP_CODE_NET_UNREACHABLE, icmp_noinfo); BUF_FREE(buf); } @@ -552,7 +560,7 @@ static void netlink_packet_deliver(struct netlink *st, st->name,s,d); free(s); free(d); - netlink_icmp_simple(st,buf,client,ICMP_TYPE_UNREACHABLE, + netlink_icmp_simple(st,buf,ICMP_TYPE_UNREACHABLE, ICMP_CODE_NET_PROHIBITED, icmp_noinfo); BUF_FREE(buf); } else { @@ -563,7 +571,7 @@ static void netlink_packet_deliver(struct netlink *st, BUF_ASSERT_FREE(buf); } else { /* Generate ICMP destination unreachable */ - netlink_icmp_simple(st,buf,client,/* client==NULL */ + netlink_icmp_simple(st,buf, ICMP_TYPE_UNREACHABLE, ICMP_CODE_NET_UNREACHABLE, icmp_noinfo); @@ -586,7 +594,7 @@ static void netlink_packet_forward(struct netlink *st, /* Packet has already been checked */ if (iph->ttl<=1) { /* Generate ICMP time exceeded */ - netlink_icmp_simple(st,buf,client,ICMP_TYPE_TIME_EXCEEDED, + netlink_icmp_simple(st,buf,ICMP_TYPE_TIME_EXCEEDED, ICMP_CODE_TTL_EXCEEDED,icmp_noinfo); BUF_FREE(buf); return; @@ -641,7 +649,7 @@ static void netlink_packet_local(struct netlink *st, Message(M_WARNING,"%s: unknown incoming ICMP\n",st->name); } else { /* Send ICMP protocol unreachable */ - netlink_icmp_simple(st,buf,client,ICMP_TYPE_UNREACHABLE, + netlink_icmp_simple(st,buf,ICMP_TYPE_UNREACHABLE, ICMP_CODE_PROTOCOL_UNREACHABLE,icmp_noinfo); BUF_FREE(buf); return; @@ -714,7 +722,7 @@ static void netlink_incoming(struct netlink *st, struct netlink_client *client, address validity and generate ICMP, etc. */ if (st->ptp) { if (client) { - st->deliver_to_host(st->dst,buf); + netlink_host_deliver(st,source,dest,buf); } else { netlink_client_deliver(st,st->clients,source,dest,buf); }