-
Notifications
You must be signed in to change notification settings - Fork 46
/
qbg_utils.c
82 lines (67 loc) · 2.51 KB
/
qbg_utils.c
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
/******************************************************************************
Implementation of ECP according to 802.1Qbg
(c) Copyright IBM Corp. 2010, 2013
Author(s): Thomas Richter <tmricht at linux.vnet.ibm.com>
This program is free software; you can redistribute it and/or modify it
under the terms and conditions of the GNU General Public License,
version 2, as published by the Free Software Foundation.
This program is distributed in the hope it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution in
the file called "COPYING".
******************************************************************************/
/*
* This file contains common support utilities for the ECP protocols.
*/
#include <stdio.h>
#include <linux/if_ether.h>
#include "lldp.h"
#include "lldp_mod.h"
#include "messages.h"
#include "qbg_utils.h"
extern int loglvl; /* Global lldpad log level */
/*
* hexdump_frame - print raw evb/ecp/vdp frame
*/
void hexdump_frame(const char *ifname, char *txt, const unsigned char *buf,
size_t len)
{
size_t i;
int left = 0;
char buffer[ETH_FRAME_LEN * 3];
/* Only collect data when the loglvl ensures data printout */
if (LOG_DEBUG < loglvl)
return;
for (i = 0; i < len; i++) {
int c;
c = snprintf(buffer + left, sizeof buffer - left, "%02x%c",
buf[i], !((i + 1) % 16) ? '\n' : ' ');
if (c > 0 && (c < (int)sizeof buffer - left))
left += c;
}
LLDPAD_DBG("%s:%s %s\n%s\n", __func__, ifname, txt, buffer);
}
/*
* Function to advertise changed variables to other modules.
*
* Parameters are interface name, target module id and data.
* When sending the data, the module call back function contains the
* module id of the sender.
*
* Return 0 when no addressee found or addressess found but addressee was
* unable to handle data.
*/
int modules_notify(int id, int sender_id, char *ifname, void *data)
{
struct lldp_module *mp = find_module_by_id(&lldp_mod_head, id);
int rc = 0;
if (mp && mp->ops->lldp_mod_notify)
rc = mp->ops->lldp_mod_notify(sender_id, ifname, data);
LLDPAD_DBG("%s:%s target-id:%#x rc:%d\n", __func__, ifname, id, rc);
return rc;
}