netlink: Break out netlink_host_deliver
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 13 Apr 2014 14:33:50 +0000 (15:33 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 24 Apr 2014 01:09:59 +0000 (02:09 +0100)
Provide a helper function for calling deliver_to_host, and use it at
the two call sites.

A side effect is that packets which came via point-to-point links are
properly counted.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
netlink.c

index 6241f70..97e1af9 100644 (file)
--- a/netlink.c
+++ b/netlink.c
@@ -445,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.  */
@@ -524,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;
@@ -713,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);
        }