summaryrefslogtreecommitdiffstats
path: root/src/plugins/vrrp/vrrp_format.c
blob: df9bf930b781986943c84042b07cb67e95b91ed0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * 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:
 */