]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
ipvs: Add hdr_flags to iphdr
authorAlex Gartrell <agartrell@fb.com>
Wed, 26 Aug 2015 16:40:29 +0000 (09:40 -0700)
committerSimon Horman <horms@verge.net.au>
Tue, 1 Sep 2015 01:33:26 +0000 (10:33 +0900)
These flags contain information like whether or not the addresses are
inverted or from icmp.  The first will allow us to drop an inverse param
all over the place, and the second will later be useful in scheduling icmp.

Signed-off-by: Alex Gartrell <agartrell@fb.com>
Acked-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Simon Horman <horms@verge.net.au>
include/net/ip_vs.h
net/netfilter/ipvs/ip_vs_core.c
net/netfilter/ipvs/ip_vs_pe_sip.c
net/netfilter/xt_ipvs.c

index 0c8309f34982e3dcc3e433490b9f60a0d0b6f62a..ac336a79ad3d38debf175454e514754a3da9e4a9 100644 (file)
@@ -29,6 +29,9 @@
 #endif
 #include <net/net_namespace.h>         /* Netw namespace */
 
+#define IP_VS_HDR_INVERSE      1
+#define IP_VS_HDR_ICMP         2
+
 /* Generic access of ipvs struct */
 static inline struct netns_ipvs *net_ipvs(struct net* net)
 {
@@ -104,6 +107,7 @@ static inline struct net *seq_file_single_net(struct seq_file *seq)
 extern int ip_vs_conn_tab_size;
 
 struct ip_vs_iphdr {
+       int hdr_flags;  /* ipvs flags */
        __u32 off;      /* Where IP or IPv4 header starts */
        __u32 len;      /* IPv4 simply where L4 starts
                         * IPv6 where L4 Transport Header starts */
@@ -127,9 +131,11 @@ static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset,
  */
 static inline int
 ip_vs_fill_iph_skb_off(int af, const struct sk_buff *skb, int offset,
-                      struct ip_vs_iphdr *iphdr)
+                      int hdr_flags, struct ip_vs_iphdr *iphdr)
 {
+       iphdr->hdr_flags = hdr_flags;
        iphdr->off = offset;
+
 #ifdef CONFIG_IP_VS_IPV6
        if (af == AF_INET6) {
                struct ipv6hdr _iph;
@@ -168,9 +174,40 @@ ip_vs_fill_iph_skb_off(int af, const struct sk_buff *skb, int offset,
 }
 
 static inline int
-ip_vs_fill_iph_skb(int af, const struct sk_buff *skb, struct ip_vs_iphdr *iphdr)
+ip_vs_fill_iph_skb_icmp(int af, const struct sk_buff *skb, int offset,
+                       bool inverse, struct ip_vs_iphdr *iphdr)
+{
+       int hdr_flags = IP_VS_HDR_ICMP;
+
+       if (inverse)
+               hdr_flags |= IP_VS_HDR_INVERSE;
+
+       return ip_vs_fill_iph_skb_off(af, skb, offset, hdr_flags, iphdr);
+}
+
+static inline int
+ip_vs_fill_iph_skb(int af, const struct sk_buff *skb, bool inverse,
+                  struct ip_vs_iphdr *iphdr)
+{
+       int hdr_flags = 0;
+
+       if (inverse)
+               hdr_flags |= IP_VS_HDR_INVERSE;
+
+       return ip_vs_fill_iph_skb_off(af, skb, skb_network_offset(skb),
+                                     hdr_flags, iphdr);
+}
+
+static inline bool
+ip_vs_iph_inverse(const struct ip_vs_iphdr *iph)
+{
+       return !!(iph->hdr_flags & IP_VS_HDR_INVERSE);
+}
+
+static inline bool
+ip_vs_iph_icmp(const struct ip_vs_iphdr *iph)
 {
-       return ip_vs_fill_iph_skb_off(af, skb, skb_network_offset(skb), iphdr);
+       return !!(iph->hdr_flags & IP_VS_HDR_ICMP);
 }
 
 static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
index b831fe84bff774d18cb7b255e40581409acab92f..4f5d3d17451771a662b638a97309f69425ded5da 100644 (file)
@@ -934,7 +934,7 @@ static int ip_vs_out_icmp(struct sk_buff *skb, int *related,
        IP_VS_DBG_PKT(11, AF_INET, pp, skb, offset,
                      "Checking outgoing ICMP for");
 
-       ip_vs_fill_iph_skb_off(AF_INET, skb, offset, &ciph);
+       ip_vs_fill_iph_skb_icmp(AF_INET, skb, offset, true, &ciph);
 
        /* The embedded headers contain source and dest in reverse order */
        cp = pp->conn_out_get(AF_INET, skb, &ciph, 1);
@@ -983,8 +983,8 @@ static int ip_vs_out_icmp_v6(struct sk_buff *skb, int *related,
                  ic->icmp6_type, ntohs(icmpv6_id(ic)),
                  &ipvsh->saddr, &ipvsh->daddr);
 
-       if (!ip_vs_fill_iph_skb_off(AF_INET6, skb, ipvsh->len + sizeof(_icmph),
-                                   &ciph))
+       if (!ip_vs_fill_iph_skb_icmp(AF_INET6, skb, ipvsh->len + sizeof(_icmph),
+                                    true, &ciph))
                return NF_ACCEPT; /* The packet looks wrong, ignore */
 
        pp = ip_vs_proto_get(ciph.protocol);
@@ -1177,7 +1177,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)
        if (!net_ipvs(net)->enable)
                return NF_ACCEPT;
 
-       ip_vs_fill_iph_skb(af, skb, &iph);
+       ip_vs_fill_iph_skb(af, skb, false, &iph);
 #ifdef CONFIG_IP_VS_IPV6
        if (af == AF_INET6) {
                if (unlikely(iph.protocol == IPPROTO_ICMPV6)) {
@@ -1212,7 +1212,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)
                                               ip_vs_defrag_user(hooknum)))
                                return NF_STOLEN;
 
-                       ip_vs_fill_iph_skb(AF_INET, skb, &iph);
+                       ip_vs_fill_iph_skb(AF_INET, skb, false, &iph);
                }
 
        /*
@@ -1407,7 +1407,7 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)
                      "Checking incoming ICMP for");
 
        offset2 = offset;
-       ip_vs_fill_iph_skb_off(AF_INET, skb, offset, &ciph);
+       ip_vs_fill_iph_skb_icmp(AF_INET, skb, offset, !ipip, &ciph);
        offset = ciph.len;
 
        /* The embedded headers contain source and dest in reverse order.
@@ -1537,7 +1537,7 @@ static int ip_vs_in_icmp_v6(struct sk_buff *skb, int *related,
                  &iph->saddr, &iph->daddr);
 
        offset = iph->len + sizeof(_icmph);
-       if (!ip_vs_fill_iph_skb_off(AF_INET6, skb, offset, &ciph))
+       if (!ip_vs_fill_iph_skb_icmp(AF_INET6, skb, offset, true, &ciph))
                return NF_ACCEPT;
 
        net = skb_net(skb);
@@ -1614,7 +1614,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
        if (unlikely((skb->pkt_type != PACKET_HOST &&
                      hooknum != NF_INET_LOCAL_OUT) ||
                     !skb_dst(skb))) {
-               ip_vs_fill_iph_skb(af, skb, &iph);
+               ip_vs_fill_iph_skb(af, skb, false, &iph);
                IP_VS_DBG_BUF(12, "packet type=%d proto=%d daddr=%s"
                              " ignored in hook %u\n",
                              skb->pkt_type, iph.protocol,
@@ -1627,7 +1627,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
        if (unlikely(sysctl_backup_only(ipvs) || !ipvs->enable))
                return NF_ACCEPT;
 
-       ip_vs_fill_iph_skb(af, skb, &iph);
+       ip_vs_fill_iph_skb(af, skb, false, &iph);
 
        /* Bad... Do not break raw sockets */
        if (unlikely(skb->sk != NULL && hooknum == NF_INET_LOCAL_OUT &&
@@ -1841,7 +1841,7 @@ ip_vs_forward_icmp_v6(const struct nf_hook_ops *ops, struct sk_buff *skb,
        struct netns_ipvs *ipvs;
        struct ip_vs_iphdr iphdr;
 
-       ip_vs_fill_iph_skb(AF_INET6, skb, &iphdr);
+       ip_vs_fill_iph_skb(AF_INET6, skb, false, &iphdr);
        if (iphdr.protocol != IPPROTO_ICMPV6)
                return NF_ACCEPT;
 
index bed5f7042529de23ef209806c7ad5607ac363a74..1b8d594e493a32f0ea461ade2d2a85387054a78d 100644 (file)
@@ -70,7 +70,7 @@ ip_vs_sip_fill_param(struct ip_vs_conn_param *p, struct sk_buff *skb)
        const char *dptr;
        int retc;
 
-       ip_vs_fill_iph_skb(p->af, skb, &iph);
+       ip_vs_fill_iph_skb(p->af, skb, false, &iph);
 
        /* Only useful with UDP */
        if (iph.protocol != IPPROTO_UDP)
index 8d47c3780fda8f98c1a16f6b6b396ec94c2bea34..370462572d8401518383e555fb5a84c5e6a08a56 100644 (file)
@@ -67,7 +67,7 @@ ipvs_mt(const struct sk_buff *skb, struct xt_action_param *par)
                goto out;
        }
 
-       ip_vs_fill_iph_skb(family, skb, &iph);
+       ip_vs_fill_iph_skb(family, skb, true, &iph);
 
        if (data->bitmask & XT_IPVS_PROTO)
                if ((iph.protocol == data->l4proto) ^