FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
vrrp_format.c
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2020 Rubicon Communications, LLC (Netgate)
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  */
7 
8 #include <vnet/vnet.h>
9 #include <vnet/api_errno.h>
10 #include <vnet/ip/ip.h>
11 #include <vnet/interface.h>
12 
13 #include <plugins/vrrp/vrrp.h>
15 
16 u8 *
17 format_vrrp_vr_flags (u8 * s, va_list * args)
18 {
19  vrrp_vr_flags_t flags = va_arg (*args, vrrp_vr_flags_t);
20 
21  s = format (s, "preempt %s accept %s unicast %s",
22  (flags & VRRP_VR_PREEMPT) ? "yes" : "no",
23  (flags & VRRP_VR_ACCEPT) ? "yes" : "no",
24  (flags & VRRP_VR_UNICAST) ? "yes" : "no");
25 
26  return s;
27 }
28 
29 u8 *
30 format_vrrp_vr_addrs (u8 * s, va_list * args)
31 {
32  int is_ipv6 = va_arg (*args, int);
33  ip46_address_t *addrs = va_arg (*args, ip46_address_t *);
34  ip46_address_t *addr;
35 
36  vec_foreach (addr, addrs)
37  {
38  s = format (s, "%U ",
40  (is_ipv6) ? (u8 *) & addr->ip6 : (u8 *) & addr->ip4);
41  }
42 
43  return s;
44 }
45 
46 u8 *
47 format_vrrp_vr_state (u8 * s, va_list * args)
48 {
49  vrrp_vr_state_t state = va_arg (*args, vrrp_vr_state_t);
50 
51  switch (state)
52  {
53 #define _(v,f,n) case VRRP_VR_STATE_##f: s = format (s, n); break;
55 #undef _
56  default:
57  s = format (s, "Unknown");
58  break;
59  }
60 
61  return s;
62 }
63 
64 u8 *
65 format_vrrp_vr_key (u8 * s, va_list * args)
66 {
67  vrrp_main_t *vmp = &vrrp_main;
68  vrrp_vr_t *vr = va_arg (*args, vrrp_vr_t *);
69  vrrp_vr_config_t *vrc = &vr->config;
70 
71  s = format (s, "[%d] sw_if_index %u VR ID %u IPv%d",
72  vr - vmp->vrs, vrc->sw_if_index,
73  vrc->vr_id, (vrc->flags & VRRP_VR_IPV6) ? 6 : 4);
74 
75  return s;
76 }
77 
78 u8 *
79 format_vrrp_vr_track_ifs (u8 * s, va_list * args)
80 {
81  vrrp_vr_tracking_if_t *track_ifs = va_arg (*args, vrrp_vr_tracking_if_t *);
82  vrrp_vr_tracking_if_t *track_if;
83 
84  vec_foreach (track_if, track_ifs)
85  s = format (s, "sw_if_index %u priority %u ",
86  track_if->sw_if_index, track_if->priority);
87 
88  return s;
89 }
90 
91 u8 *
92 format_vrrp_vr (u8 * s, va_list * args)
93 {
94  vrrp_vr_t *vr = va_arg (*args, vrrp_vr_t *);
95 
96  s = format (s, "%U\n", format_vrrp_vr_key, vr);
97 
98  s = format (s, " state %U flags: %U\n",
101  s = format (s, " priority: configured %u adjusted %u\n",
102  vr->config.priority, vrrp_vr_priority (vr));
103  s = format (s, " timers: adv interval %u "
104  "master adv %u skew %u master down %u\n",
107 
108  s = format (s, " virtual MAC %U\n", format_ethernet_address,
109  &vr->runtime.mac);
110 
111  s = format (s, " addresses %U\n", format_vrrp_vr_addrs,
112  (vr->config.flags & VRRP_VR_IPV6) != 0, vr->config.vr_addrs);
113 
114  s = format (s, " peer addresses %U\n", format_vrrp_vr_addrs,
115  (vr->config.flags & VRRP_VR_IPV6) != 0, vr->config.peer_addrs);
116 
117  s = format (s, " tracked interfaces %U\n", format_vrrp_vr_track_ifs,
118  vr->tracking.interfaces);
119 
120  return s;
121 }
122 
123 u8 *
124 format_vrrp_packet_hdr (u8 * s, va_list * args)
125 {
126  vrrp_header_t *pkt = va_arg (*args, vrrp_header_t *);
127  u32 version = pkt->vrrp_version_and_type >> 4;
128 
129  s = format (s, "ver %u, type %u, VRID %u, prio %u, "
130  "n_addrs %u, interval %u%ss, csum 0x%x",
131  version, pkt->vrrp_version_and_type & 0xf,
132  pkt->vr_id, pkt->priority, pkt->n_addrs,
133  clib_net_to_host_u16 (pkt->rsvd_and_max_adv_int),
134  (version == 3) ? "c" : "", pkt->checksum);
135 
136  return s;
137 }
138 
139 
140 /*
141  * fd.io coding-style-patch-verification: ON
142  *
143  * Local Variables:
144  * eval: (c-set-style "gnu")
145  * End:
146  */
u32 sw_if_index
Definition: vrrp.h:71
vrrp_vr_tracking_t tracking
Definition: vrrp.h:110
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:103
Definition: vrrp.h:106
option version
Definition: sample.api:19
u8 * format_vrrp_vr_track_ifs(u8 *s, va_list *args)
Definition: vrrp_format.c:79
vrrp_vr_t * vrs
Definition: vrrp.h:151
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
vrrp_vr_state_t state
Definition: vrrp.h:96
u8 * format_vrrp_vr_state(u8 *s, va_list *args)
Definition: vrrp_format.c:47
vhost_vring_addr_t addr
Definition: vhost_user.h:111
unsigned char u8
Definition: types.h:56
format_function_t format_ip4_address
Definition: format.h:73
u16 master_adv_int
Definition: vrrp.h:97
u8 * format_vrrp_packet_hdr(u8 *s, va_list *args)
Definition: vrrp_format.c:124
u8 * format_ethernet_address(u8 *s, va_list *args)
Definition: format.c:44
vrrp_vr_config_t config
Definition: vrrp.h:108
u8 * format_vrrp_vr_addrs(u8 *s, va_list *args)
Definition: vrrp_format.c:30
unsigned int u32
Definition: types.h:88
u16 skew
Definition: vrrp.h:98
u16 master_down_int
Definition: vrrp.h:99
mac_address_t mac
Definition: vrrp.h:100
u8 priority
Definition: vrrp.h:73
vrrp_vr_flags_t flags
Definition: vrrp.h:75
u8 vr_id
Definition: vrrp.h:72
vrrp_vr_runtime_t runtime
Definition: vrrp.h:109
u8 * format_vrrp_vr_key(u8 *s, va_list *args)
Definition: vrrp_format.c:65
format_function_t format_ip6_address
Definition: format.h:91
static u8 vrrp_vr_priority(vrrp_vr_t *vr)
Definition: vrrp.h:355
vrrp_main_t vrrp_main
Definition: vrrp.c:25
u8 * format_vrrp_vr(u8 *s, va_list *args)
Definition: vrrp_format.c:92
vrrp_vr_tracking_if_t * interfaces
Definition: vrrp.h:65
u8 * format_vrrp_vr_flags(u8 *s, va_list *args)
Definition: vrrp_format.c:17
enum vrrp_vr_flags vrrp_vr_flags_t
enum vrrp_vr_state vrrp_vr_state_t
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
#define vec_foreach(var, vec)
Vector iterator.
ip46_address_t * vr_addrs
Definition: vrrp.h:76
bool is_ipv6
Definition: dhcp.api:202
u16 adv_interval
Definition: vrrp.h:74
ip46_address_t * peer_addrs
Definition: vrrp.h:77