Line data Source code
1 : /* SPDX-License-Identifier: Apache-2.0
2 : * Copyright(c) 2021 Cisco Systems, Inc.
3 : */
4 :
5 : #include <vlib/vlib.h>
6 : #include <vnet/vnet.h>
7 : #include <vnet/interface.h>
8 :
9 559 : VLIB_REGISTER_LOG_CLASS (if_caps_log, static) = {
10 : .class_name = "interface",
11 : .subclass_name = "caps",
12 : };
13 :
14 : #define log_debug(fmt, ...) \
15 : vlib_log_debug (if_caps_log.class, fmt, __VA_ARGS__)
16 :
17 : format_function_t format_vnet_hw_if_caps;
18 :
19 : void
20 583 : vnet_hw_if_change_caps (vnet_main_t *vnm, u32 hw_if_index,
21 : vnet_hw_if_caps_change_t *caps)
22 : {
23 583 : vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
24 583 : vnet_hw_if_caps_t old = hi->caps;
25 :
26 583 : hi->caps = (hi->caps & ~caps->mask) | caps->val;
27 :
28 583 : log_debug ("change: interface %U, set: %U, cleared: %U",
29 : format_vnet_hw_if_index_name, vnm, hw_if_index,
30 : format_vnet_hw_if_caps, (old ^ hi->caps) & caps->val,
31 : format_vnet_hw_if_caps, (old ^ hi->caps) & ~caps->val);
32 583 : }
33 :
34 : u8 *
35 0 : format_vnet_hw_if_caps (u8 *s, va_list *va)
36 : {
37 0 : vnet_hw_if_caps_t caps = va_arg (*va, vnet_hw_if_caps_t);
38 :
39 0 : const char *strings[sizeof (vnet_hw_if_caps_t) * 8] = {
40 : #define _(bit, sfx, str) [bit] = (str),
41 : foreach_vnet_hw_if_caps
42 : #undef _
43 : };
44 :
45 0 : if (caps == 0)
46 0 : return format (s, "none");
47 :
48 0 : while (caps)
49 : {
50 0 : int bit = get_lowest_set_bit_index (caps);
51 :
52 0 : if (strings[bit])
53 0 : s = format (s, "%s", strings[bit]);
54 : else
55 0 : s = format (s, "unknown-%u", bit);
56 :
57 0 : caps = clear_lowest_set_bit (caps);
58 0 : if (caps)
59 0 : vec_add1 (s, ' ');
60 : }
61 :
62 0 : return s;
63 : }
|