summaryrefslogtreecommitdiffstats
path: root/src/vnet/dns
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2017-11-15 13:28:15 -0500
committerDave Barach <dave@barachs.net>2017-11-15 13:28:43 -0500
commitb8a0d2cf9ff8796123b3c167c051f78ab03cc4cf (patch)
tree69226e5206458c9c12e83fae1abd4bd34e0d04ff /src/vnet/dns
parent5665a22f81dd48c6d211a9a2be83d174c62d73cf (diff)
Punt DNS request/reply traffic when name resolution disabled
Change-Id: Iaad22f25993783be57247aa1f050740f96d2566a Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vnet/dns')
-rw-r--r--src/vnet/dns/dns.h1
-rw-r--r--src/vnet/dns/reply_node.c15
-rw-r--r--src/vnet/dns/request_node.c16
3 files changed, 27 insertions, 5 deletions
diff --git a/src/vnet/dns/dns.h b/src/vnet/dns/dns.h
index 84d7ee041b5..1272e756d7c 100644
--- a/src/vnet/dns/dns.h
+++ b/src/vnet/dns/dns.h
@@ -139,6 +139,7 @@ typedef enum
} dns46_request_error_t;
#define foreach_dns46_reply_error \
+_(DISABLED, "DNS pkts punted (feature disabled)") \
_(PROCESSED, "DNS reply pkts processed") \
_(NO_ELT, "No DNS pool element") \
_(FORMAT_ERROR, "DNS format errors") \
diff --git a/src/vnet/dns/reply_node.c b/src/vnet/dns/reply_node.c
index fbb99e8a6f9..5681e11d8e2 100644
--- a/src/vnet/dns/reply_node.c
+++ b/src/vnet/dns/reply_node.c
@@ -50,6 +50,7 @@ static char *dns46_reply_error_strings[] = {
typedef enum
{
DNS46_REPLY_NEXT_DROP,
+ DNS46_REPLY_NEXT_PUNT,
DNS46_REPLY_N_NEXT,
} dns46_reply_next_t;
@@ -59,6 +60,7 @@ dns46_reply_node_fn (vlib_main_t * vm,
{
u32 n_left_from, *from, *to_next;
dns46_reply_next_t next_index;
+ dns_main_t *dm = &dns_main;
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
@@ -139,8 +141,8 @@ dns46_reply_node_fn (vlib_main_t * vm,
vlib_buffer_t *b0;
u32 next0 = DNS46_REPLY_NEXT_DROP;
dns_header_t *d0;
- u32 pool_index0;
- u32 error0;
+ u32 pool_index0 = ~0;
+ u32 error0 = 0;
u8 *resp0 = 0;
/* speculatively enqueue b0 to the current next frame */
@@ -149,11 +151,16 @@ dns46_reply_node_fn (vlib_main_t * vm,
from += 1;
to_next += 1;
n_left_from -= 1;
-
n_left_to_next -= 1;
b0 = vlib_get_buffer (vm, bi0);
d0 = vlib_buffer_get_current (b0);
+ if (PREDICT_FALSE (dm->is_enabled == 0))
+ {
+ next0 = DNS46_REPLY_NEXT_PUNT;
+ error0 = DNS46_REPLY_ERROR_DISABLED;
+ goto done0;
+ }
pool_index0 = clib_host_to_net_u16 (d0->id);
@@ -169,6 +176,7 @@ dns46_reply_node_fn (vlib_main_t * vm,
(uword) resp0);
error0 = DNS46_REPLY_ERROR_PROCESSED;
+ done0:
b0->error = node->errors[error0];
if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
@@ -205,6 +213,7 @@ VLIB_REGISTER_NODE (dns46_reply_node) =
.n_next_nodes = DNS46_REPLY_N_NEXT,
.next_nodes = {
[DNS46_REPLY_NEXT_DROP] = "error-drop",
+ [DNS46_REPLY_NEXT_PUNT] = "error-punt",
},
};
/* *INDENT-ON* */
diff --git a/src/vnet/dns/request_node.c b/src/vnet/dns/request_node.c
index 64468805237..f7446cce825 100644
--- a/src/vnet/dns/request_node.c
+++ b/src/vnet/dns/request_node.c
@@ -51,6 +51,7 @@ typedef enum
{
DNS46_REQUEST_NEXT_DROP,
DNS46_REQUEST_NEXT_IP_LOOKUP,
+ DNS46_REQUEST_NEXT_PUNT,
DNS46_REQUEST_N_NEXT,
} dns46_request_next_t;
@@ -160,15 +161,22 @@ dns46_request_inline (vlib_main_t * vm,
from += 1;
to_next += 1;
n_left_from -= 1;
-
n_left_to_next -= 1;
b0 = vlib_get_buffer (vm, bi0);
d0 = vlib_buffer_get_current (b0);
u0 = (udp_header_t *) ((u8 *) d0 - sizeof (*u0));
+
+ if (PREDICT_FALSE (dm->is_enabled == 0))
+ {
+ next0 = DNS46_REQUEST_NEXT_PUNT;
+ goto done0;
+ }
+
if (is_ip6)
{
- ip60 = (ip6_header_t *) (((u8 *) u0) - sizeof (ip4_header_t));
+ ip60 = (ip6_header_t *) (((u8 *) u0) - sizeof (ip6_header_t));
+ next0 = DNS46_REQUEST_NEXT_DROP;
error0 = DNS46_REQUEST_ERROR_UNIMPLEMENTED;
goto done0;
}
@@ -187,11 +195,13 @@ dns46_request_inline (vlib_main_t * vm,
/* Requests only */
if (flags0 & DNS_QR)
{
+ next0 = DNS46_REQUEST_NEXT_DROP;
error0 = DNS46_REQUEST_ERROR_BAD_REQUEST;
goto done0;
}
if (clib_net_to_host_u16 (d0->qdcount) != 1)
{
+ next0 = DNS46_REQUEST_NEXT_DROP;
error0 = DNS46_REQUEST_ERROR_TOO_MANY_REQUESTS;
goto done0;
}
@@ -286,6 +296,7 @@ VLIB_REGISTER_NODE (dns4_request_node) =
.n_next_nodes = DNS46_REQUEST_N_NEXT,
.next_nodes = {
[DNS46_REQUEST_NEXT_DROP] = "error-drop",
+ [DNS46_REQUEST_NEXT_PUNT] = "error-punt",
[DNS46_REQUEST_NEXT_IP_LOOKUP] = "ip4-lookup",
},
};
@@ -312,6 +323,7 @@ VLIB_REGISTER_NODE (dns6_request_node) =
.n_next_nodes = DNS46_REQUEST_N_NEXT,
.next_nodes = {
[DNS46_REQUEST_NEXT_DROP] = "error-drop",
+ [DNS46_REQUEST_NEXT_PUNT] = "error-punt",
[DNS46_REQUEST_NEXT_IP_LOOKUP] = "ip6-lookup",
},
};
ral.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * ip4/ip_checksum.c: ip/tcp/udp checksums
 *
 * Copyright (c) 2008 Eliot Dresselhaus
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include <vnet/ip/ip.h>

ip_csum_t
ip_incremental_checksum (ip_csum_t sum, void *_data, uword n_bytes)
{
  uword data = pointer_to_uword (_data);
  ip_csum_t sum0, sum1;

  sum0 = 0;
  sum1 = sum;

  /* Align data pointer to 64 bits. */
#define _(t)					\
do {						\
  if (n_bytes >= sizeof (t)			\
      && sizeof (t) < sizeof (ip_csum_t)	\
      && (data % (2 * sizeof (t))) != 0)	\
    {						\
      sum0 += * uword_to_pointer (data, t *);	\
      data += sizeof (t);			\
      n_bytes -= sizeof (t);			\
    }						\
} while (0)

  _(u8);
  _(u16);
  if (BITS (ip_csum_t) > 32)
    _(u32);

#undef _

  {
    ip_csum_t *d = uword_to_pointer (data, ip_csum_t *);

    while (n_bytes >= 2 * sizeof (d[0]))
      {
	sum0 = ip_csum_with_carry (sum0, d[0]);
	sum1 = ip_csum_with_carry (sum1, d[1]);
	d += 2;
	n_bytes -= 2 * sizeof (d[0]);
      }

    data = pointer_to_uword (d);
  }

#define _(t)								\
do {									\
  if (n_bytes >= sizeof (t) && sizeof (t) <= sizeof (ip_csum_t))	\
    {									\
      sum0 = ip_csum_with_carry (sum0, * uword_to_pointer (data, t *));	\
      data += sizeof (t);						\
      n_bytes -= sizeof (t);						\
    }									\
} while (0)

  if (BITS (ip_csum_t) > 32)
    _(u64);
  _(u32);
  _(u16);
  _(u8);

#undef _

  /* Combine even and odd sums. */
  sum0 = ip_csum_with_carry (sum0, sum1);

  return sum0;
}

ip_csum_t
ip_csum_and_memcpy (ip_csum_t sum, void *dst, void *src, uword n_bytes)
{
  uword n_left;
  ip_csum_t sum0 = sum, sum1;
  n_left = n_bytes;

  if (n_left && (pointer_to_uword (dst) & sizeof (u8)))
    {
      u8 *d8, val;

      d8 = dst;
      val = ((u8 *) src)[0];
      d8[0] = val;
      dst += 1;
      src += 1;
      n_left -= 1;
      sum0 =
	ip_csum_with_carry (sum0, val << (8 * CLIB_ARCH_IS_LITTLE_ENDIAN));
    }

  while ((n_left >= sizeof (u16))
	 && (pointer_to_uword (dst) & (sizeof (sum) - sizeof (u16))))
    {
      u16 *d16, *s16;

      d16 = dst;
      s16 = src;

      d16[0] = clib_mem_unaligned (&s16[0], u16);

      sum0 = ip_csum_with_carry (sum0, d16[0]);
      dst += sizeof (u16);
      src += sizeof (u16);
      n_left -= sizeof (u16);
    }

  sum1 = 0;
  while (n_left >= 2 * sizeof (sum))
    {
      ip_csum_t dst0, dst1;
      ip_csum_t *dst_even, *src_even;

      dst_even = dst;
      src_even = src;
      dst0 = clib_mem_unaligned (&src_even[0], ip_csum_t);
      dst1 = clib_mem_unaligned (&src_even[1], ip_csum_t);

      dst_even[0] = dst0;
      dst_even[1] = dst1;

      dst += 2 * sizeof (dst_even[0]);
      src += 2 * sizeof (dst_even[0]);
      n_left -= 2 * sizeof (dst_even[0]);

      sum0 = ip_csum_with_carry (sum0, dst0);
      sum1 = ip_csum_with_carry (sum1, dst1);
    }

  sum0 = ip_csum_with_carry (sum0, sum1);
  while (n_left >= 1 * sizeof (sum))
    {
      ip_csum_t dst0, *dst_even, *src_even;

      dst_even = dst;
      src_even = src;

      dst0 = clib_mem_unaligned (&src_even[0], ip_csum_t);

      dst_even[0] = dst0;

      dst += 1 * sizeof (sum);
      src += 1 * sizeof (sum);
      n_left -= 1 * sizeof (sum);

      sum0 = ip_csum_with_carry (sum0, dst0);
    }

  while (n_left >= sizeof (u16))
    {
      u16 dst0, *dst_short, *src_short;

      dst_short = dst;
      src_short = src;

      dst0 = clib_mem_unaligned (&src_short[0], u16);

      dst_short[0] = dst0;

      sum0 = ip_csum_with_carry (sum0, dst_short[0]);
      dst += 1 * sizeof (dst0);
      src += 1 * sizeof (dst0);
      n_left -= 1 * sizeof (dst0);

    }

  if (n_left == 1)
    {
      u8 *d8, *s8, val;

      d8 = dst;
      s8 = src;

      d8[0] = val = s8[0];
      d8 += 1;
      s8 += 1;
      n_left -= 1;
      sum0 = ip_csum_with_carry (sum0, val << (8 * CLIB_ARCH_IS_BIG_ENDIAN));
    }

  return sum0;
}

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */