aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/osi/plugin.c
blob: 5fc412e093e423841b35eea3efa417994618b2ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
 * plugin.c: osi
 *
 * Copyright (c) 2023 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.
 */
#include <vlib/vlib.h>
#include <vnet/plugin/plugin.h>
#include <vpp/app/version.h>
VLIB_PLUGIN_REGISTER () = {
  .version = VPP_BUILD_VER,
  .description = "OSI plugin",
};
l.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 2019-2020 Rubicon Communications, LLC (Netgate)
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 */

#include <vnet/vnet.h>
#include <vnet/api_errno.h>
#include <vnet/ip/ip.h>
#include <vnet/interface.h>

#include <plugins/vrrp/vrrp.h>
#include <plugins/vrrp/vrrp_packet.h>

u8 *
format_vrrp_vr_flags (u8 * s, va_list * args)
{
  vrrp_vr_flags_t flags = va_arg (*args, vrrp_vr_flags_t);

  s = format (s, "preempt %s accept %s unicast %s",
	      (flags & VRRP_VR_PREEMPT) ? "yes" : "no",
	      (flags & VRRP_VR_ACCEPT) ? "yes" : "no",
	      (flags & VRRP_VR_UNICAST) ? "yes" : "no");

  return s;
}

u8 *
format_vrrp_vr_addrs (u8 * s, va_list * args)
{
  int is_ipv6 = va_arg (*args, int);
  ip46_address_t *addrs = va_arg (*args, ip46_address_t *);
  ip46_address_t *addr;

  vec_foreach (addr, addrs)
  {
    s = format (s, "%U ",
		(is_ipv6) ? format_ip6_address : format_ip4_address,
		(is_ipv6) ? (u8 *) & addr->ip6 : (u8 *) & addr->ip4);
  }

  return s;
}

u8 *
format_vrrp_vr_state (u8 * s, va_list * args)
{
  vrrp_vr_state_t state = va_arg (*args, vrrp_vr_state_t);

  switch (state)
    {
#define _(v,f,n) case VRRP_VR_STATE_##f: s = format (s, n); break;
      foreach_vrrp_vr_state
#undef _
    default:
      s = format (s, "Unknown");
      break;
    }

  return s;
}

u8 *
format_vrrp_vr_key (u8 * s, va_list * args)
{
  vrrp_main_t *vmp = &vrrp_main;
  vrrp_vr_t *vr = va_arg (*args, vrrp_vr_t *);
  vrrp_vr_config_t *vrc = &vr->config;

  s = format (s, "[%d] sw_if_index %u VR ID %u IPv%d",
	      vr - vmp->vrs, vrc->sw_if_index,
	      vrc->vr_id, (vrc->flags & VRRP_VR_IPV6) ? 6 : 4);

  return s;
}

u8 *
format_vrrp_vr_track_ifs (u8 * s, va_list * args)
{
  vrrp_vr_tracking_if_t *track_ifs = va_arg (*args, vrrp_vr_tracking_if_t *);
  vrrp_vr_tracking_if_t *track_if;

  vec_foreach (track_if, track_ifs)
    s = format (s, "sw_if_index %u priority %u ",
		track_if->sw_if_index, track_if->priority);

  return s;
}

u8 *
format_vrrp_vr (u8 * s, va_list * args)
{
  vrrp_vr_t *vr = va_arg (*args, vrrp_vr_t *);

  s = format (s, "%U\n", format_vrrp_vr_key, vr);

  s = format (s, "   state %U flags: %U\n",
	      format_vrrp_vr_state, vr->runtime.state,
	      format_vrrp_vr_flags, vr->config.flags);
  s = format (s, "   priority: configured %u adjusted %u\n",
	      vr->config.priority, vrrp_vr_priority (vr));
  s = format (s, "   timers: adv interval %u "
	      "master adv %u skew %u master down %u\n",
	      vr->config.adv_interval, vr->runtime.master_adv_int,
	      vr->runtime.skew, vr->runtime.master_down_int);

  s = format (s, "   virtual MAC %U\n", format_ethernet_address,
	      &vr->runtime.mac);

  s = format (s, "   addresses %U\n", format_vrrp_vr_addrs,
	      (vr->config.flags & VRRP_VR_IPV6) != 0, vr->config.vr_addrs);

  s = format (s, "   peer addresses %U\n", format_vrrp_vr_addrs,
	      (vr->config.flags & VRRP_VR_IPV6) != 0, vr->config.peer_addrs);

  s = format (s, "   tracked interfaces %U\n", format_vrrp_vr_track_ifs,
	      vr->tracking.interfaces);

  return s;
}

u8 *
format_vrrp_packet_hdr (u8 * s, va_list * args)
{
  vrrp_header_t *pkt = va_arg (*args, vrrp_header_t *);
  u32 version = pkt->vrrp_version_and_type >> 4;

  s = format (s, "ver %u, type %u, VRID %u, prio %u, "
	      "n_addrs %u, interval %u%ss, csum 0x%x",
	      version, pkt->vrrp_version_and_type & 0xf,
	      pkt->vr_id, pkt->priority, pkt->n_addrs,
	      clib_net_to_host_u16 (pkt->rsvd_and_max_adv_int),
	      (version == 3) ? "c" : "", pkt->checksum);

  return s;
}


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