-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
66 lines (61 loc) · 1.63 KB
/
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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <arpa/inet.h>
#include "ancp.h"
#include "logg.h"
/* Convert ANCP adjacency message code to string */
char *adj_code_str(adj_code_t c)
{
switch (c) {
case SYN : return "SYN";
case SYNACK: return "SYNACK";
case ACK: return "ACK";
case RSTACK: return "RSTACK";
default: return "Unknown";
}
}
/* Convert ANCP protocol state to string */
char* state_str(state_t s)
{
switch(s) {
case START: return "START";
case SYNSENT: return "SYNSENT";
case SYNRCVD: return "SYNRCVD";
case ESTAB: return "ESTAB";
default: return "Unknown";
}
}
char* cap_str (capability_t c)
{
switch(c) {
case DYN_TOPO_DISC : return "TOPO-DISC";
case LINE_CONFIG: return "LINE-CONFIG";
case MULTICAST: return "MULTICAST";
case OAM: return "OAM";
default: return "Unknown";
}
}
/* Return the ANCP adjacency message code from the incoming message
iff it is a valid Adjacency message */
adj_code_t get_adj_mtype (unsigned char *p)
{
adj_msg_hdr_t *hdr;
uint8_t code;
if (!p) {
DEBUG_ERR("Null message passed to get adj type!\n");
return UNKNOWN;
}
hdr = (adj_msg_hdr_t*) p;
if (hdr->gsmp_hdr.ether_type == ntohs(GSMP_TYPE)) {
code = (hdr->m_code & 0x7F); /* Mask off the M flag */
#if 0
printf ("\n get_adj_mtype: GSMP msg[%s], len = %d\n",
adj_code_str(code),
ntohs(hdr->gsmp_hdr.length));
#endif
return code;
}
return UNKNOWN;
}