FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
builtins.c
Go to the documentation of this file.
1 #include <vnet/vnet.h>
4 #include <mactime/mactime.h>
5 #include <vlib/unix/plugin.h>
7 
8 static walk_rc_t
10 {
11  mactime_main_t *mm = ctx;
12 
13  vec_add1 (mm->arp_cache_copy, ipni);
14 
15  return (WALK_CONTINUE);
16 }
17 
18 static int
20  u8 * request, http_session_t * hs)
21 {
23  mactime_device_t *dp;
24  u8 *macstring = 0;
25  char *status_string;
26  u32 *pool_indices = 0;
27  int current_status = 99;
28  int i, j;
29  f64 now;
30  vlib_counter_t allow, drop;
31  ip_neighbor_t *n;
32  char *q = "\"";
33  u8 *s = 0;
34  int need_comma = 0;
35 
36  /* Walk all ip4 neighbours on all interfaces */
39 
41 
42  if (PREDICT_FALSE ((now - mm->sunday_midnight) > 86400.0 * 7.0))
44 
45  pool_foreach (dp, mm->devices)
46  {
47  vec_add1 (pool_indices, dp - mm->devices);
48  }
49 
50  s = format (s, "{%smactime%s: [\n", q, q);
51 
52  for (i = 0; i < vec_len (pool_indices); i++)
53  {
54  dp = pool_elt_at_index (mm->devices, pool_indices[i]);
55 
56  /* Check dynamic ranges */
57  for (j = 0; j < vec_len (dp->ranges); j++)
58  {
59  clib_timebase_range_t *r = dp->ranges + j;
60  f64 start0, end0;
61 
62  start0 = r->start + mm->sunday_midnight;
63  end0 = r->end + mm->sunday_midnight;
64 
65  if (now >= start0 && now <= end0)
66  {
68  current_status = 3;
70  current_status = 5;
71  else
72  current_status = 2;
73  goto print;
74  }
75  }
77  current_status = 0;
79  current_status = 1;
81  current_status = 2;
83  current_status = 3;
85  current_status = 4;
86 
87  print:
88  vec_reset_length (macstring);
89 
90  macstring = format (0, "%U", format_mac_address, dp->mac_address);
91 
92  if (need_comma)
93  s = format (s, "},\n");
94 
95  need_comma = 1;
96  s = format (s, "{%smac_address%s: %s%s%s, ", q, q, q, macstring, q);
97 
98  switch (current_status)
99  {
100  case 0:
101  status_string = "static drop";
102  break;
103  case 1:
104  status_string = "static allow";
105  break;
106  case 2:
107  status_string = "dynamic drop";
108  break;
109  case 3:
110  status_string = "dynamic allow";
111  break;
112  case 4:
113  status_string = "d-quota inact";
114  break;
115  case 5:
116  status_string = "d-quota activ";
117  break;
118  default:
119  status_string = "code bug!";
120  break;
121  }
123  &allow);
124  vlib_get_combined_counter (&mm->drop_counters, dp - mm->devices, &drop);
125  s = format (s, "%sname%s: %s%s%s, %sstatus%s: %s%s%s,",
126  q, q, q, dp->device_name, q, q, q, q, status_string, q);
127  s = format (s, "%sallow_pkts%s: %lld,", q, q, allow.packets);
128  s = format (s, "%sallow_bytes%s: %lld,", q, q, allow.bytes);
129  s = format (s, "%sdrop_pkts%s: %lld", q, q, drop.packets);
130 
131  for (j = 0; j < vec_len (mm->arp_cache_copy); j++)
132  {
133  n = ip_neighbor_get (mm->arp_cache_copy[j]);
134  if (!memcmp (dp->mac_address,
135  ip_neighbor_get_mac (n), sizeof (mac_address_t)))
136  {
137  s = format (s, ", %sip4_address%s: %s%U%s", q, q,
140  break;
141  }
142  }
143  }
144  if (need_comma)
145  s = format (s, "}\n");
146  s = format (s, "]}\n");
147  vec_free (macstring);
148  vec_free (pool_indices);
149 
150  hs->data = s;
151  hs->data_offset = 0;
152  hs->cache_pool_index = ~0;
153  hs->free_data = 1;
154  return 0;
155 }
156 
157 void
159 {
160  void (*fp) (void *, char *, int);
161 
162  /* Look up the builtin URL registration handler */
163  fp = vlib_get_plugin_symbol ("http_static_plugin.so",
164  "http_static_server_register_builtin_handler");
165 
166  if (fp == 0)
167  {
168  clib_warning ("http_static_plugin.so not loaded...");
169  return;
170  }
171 
172  (*fp) (handle_get_mactime, "mactime.json", HTTP_BUILTIN_METHOD_GET);
173 }
174 
175 /*
176  * fd.io coding-style-patch-verification: ON
177  *
178  * Local Variables:
179  * eval: (c-set-style "gnu")
180  * End:
181  */
ip_neighbor_t_
A representation of an IP neighbour/peer.
Definition: ip_neighbor_types.h:59
vec_reset_length
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
Definition: vec_bootstrap.h:194
mactime_main_t::timebase
clib_timebase_t timebase
Definition: mactime.h:49
MACTIME_DEVICE_FLAG_DYNAMIC_DROP
#define MACTIME_DEVICE_FLAG_DYNAMIC_DROP
Definition: mactime_device.h:40
HTTP_BUILTIN_METHOD_GET
@ HTTP_BUILTIN_METHOD_GET
Definition: http_static.h:76
WALK_CONTINUE
@ WALK_CONTINUE
Definition: interface_funcs.h:174
http_session_t::data_offset
u32 data_offset
Current data send offset.
Definition: http_static.h:104
ip_neighbor_get_ip
const ip_address_t * ip_neighbor_get_ip(const ip_neighbor_t *ipn)
Definition: ip_neighbor.c:116
http_builtin_method_type_t
http_builtin_method_type_t
Definition: http_static.h:74
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
ip_neighbor_get
ip_neighbor_t * ip_neighbor_get(index_t ipni)
Definition: ip_neighbor.c:89
MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA
#define MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA
Definition: mactime_device.h:42
mactime_device_t::device_name
u8 * device_name
Definition: mactime_device.h:27
mactime_main_t::drop_counters
vlib_combined_counter_main_t drop_counters
Definition: mactime.h:63
MACTIME_DEVICE_FLAG_STATIC_DROP
#define MACTIME_DEVICE_FLAG_STATIC_DROP
Always drop packets from this device.
Definition: mactime_device.h:38
IP46_TYPE_IP4
@ IP46_TYPE_IP4
Definition: ip46_address.h:26
http_static.h
mactime_device_t::mac_address
u8 mac_address[6]
Definition: mactime_device.h:28
MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW
#define MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW
Definition: mactime_device.h:41
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
AF_IP4
@ AF_IP4
Definition: ip_types.h:23
plugin.h
clib_timebase_range_t
Definition: time_range.h:49
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1071
format_mac_address
u8 * format_mac_address(u8 *s, va_list *args)
Definition: format.c:58
mactime_device_t
Definition: mactime_device.h:25
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
mactime.h
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
vlib_counter_t
Combined counter to hold both packets and byte differences.
Definition: counter_types.h:26
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
mactime_device_t::ranges
clib_timebase_range_t * ranges
Definition: mactime_device.h:34
mactime_main_t::sunday_midnight
f64 sunday_midnight
Definition: mactime.h:52
print
static unsigned char * print(const cJSON *const item, cJSON_bool format, const internal_hooks *const hooks)
Definition: cJSON.c:1183
http_session_t::free_data
int free_data
Need to free data in detach_cache_entry.
Definition: http_static.h:106
ip_neighbor_get_mac
const mac_address_t * ip_neighbor_get_mac(const ip_neighbor_t *ipn)
Definition: ip_neighbor.c:128
ip_neighbor_walk
void ip_neighbor_walk(ip_address_family_t af, u32 sw_if_index, ip_neighbor_walk_cb_t cb, void *ctx)
Definition: ip_neighbor.c:1041
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
mactime_main_t::allow_counters
vlib_combined_counter_main_t allow_counters
Definition: mactime.h:62
f64
double f64
Definition: types.h:142
mactime_ip_neighbor_copy
static walk_rc_t mactime_ip_neighbor_copy(index_t ipni, void *ctx)
Definition: builtins.c:9
http_session_t::data
u8 * data
File data, a vector.
Definition: http_static.h:102
http_session_t
Application session.
Definition: http_server.c:40
http_session_t::cache_pool_index
u32 cache_pool_index
File cache pool index.
Definition: http_static.h:109
mactime_device_t::flags
u32 flags
Definition: mactime_device.h:31
vlib_counter_t::packets
counter_t packets
packet counter
Definition: counter_types.h:28
mactime_main_t::devices
mactime_device_t * devices
Definition: mactime.h:58
request
vhost_user_req_t request
Definition: vhost_user.h:123
vlib_get_combined_counter
static void vlib_get_combined_counter(const vlib_combined_counter_main_t *cm, u32 index, vlib_counter_t *result)
Get the value of a combined counter, never called in the speed path Scrapes the entire set of per-thr...
Definition: counter.h:272
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
ip_neighbor.h
mactime_url_init
void mactime_url_init(vlib_main_t *vm)
Definition: builtins.c:158
format
description fragment has unexpected format
Definition: map.api:433
format_ip46_address
format_function_t format_ip46_address
Definition: ip46_address.h:50
mactime_main
mactime_main_t mactime_main
Definition: mactime.c:38
u32
unsigned int u32
Definition: types.h:88
clib_timebase_now
static f64 clib_timebase_now(clib_timebase_t *tb)
Definition: time_range.h:88
vlib_counter_t::bytes
counter_t bytes
byte counter
Definition: counter_types.h:29
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
mactime_main_t
Definition: mactime.h:43
mac_address_t_
Definition: mac_address.h:21
MACTIME_DEVICE_FLAG_STATIC_ALLOW
#define MACTIME_DEVICE_FLAG_STATIC_ALLOW
Definition: mactime_device.h:39
now
f64 now
Definition: nat44_ei_out2in.c:710
mactime_main_t::arp_cache_copy
index_t * arp_cache_copy
Definition: mactime.h:74
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_warning
#define clib_warning(format, args...)
Definition: error.h:59
builtinurl.h
vnet.h
clib_timebase_find_sunday_midnight
__clib_export f64 clib_timebase_find_sunday_midnight(f64 start_time)
Definition: time_range.c:221
handle_get_mactime
static int handle_get_mactime(http_builtin_method_type_t reqtype, u8 *request, http_session_t *hs)
Definition: builtins.c:19
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
vlib_get_plugin_symbol
void * vlib_get_plugin_symbol(char *plugin_name, char *symbol_name)
Definition: plugin.c:38