-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnet.h
More file actions
73 lines (53 loc) · 1.74 KB
/
net.h
File metadata and controls
73 lines (53 loc) · 1.74 KB
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
#ifndef __NET__
#define __NET__
#include "utils.h"
#include <memory.h>
typedef struct graph_ graph_t;
typedef struct interface_ interface_t;
typedef struct node_ node_t;
typedef struct ip_add_{
char ip_addr[16];
} ip_add_t;
typedef struct mac_add_{
char mac[8];
} mac_add_t;
typedef struct node_nw_prop_{
unsigned int flags;
//L3 properties
bool_t is_lb_addr_config;
// loopback address of node
ip_add_t lb_addr;
} node_nw_prop_t;
static inline void init_node_nw_prop(node_nw_prop_t* node_nw_prop){
node_nw_prop->flags = 0;
node_nw_prop->is_lb_addr_config = FALSE;
memset(node_nw_prop->lb_addr.ip_addr, 0, 16);
}
typedef struct intf_nw_props_ {
//L2 properties
mac_add_t mac_add;
//L3 properties
bool_t is_ipadd_config;
ip_add_t ip_add;
char mask;
} intf_nw_props_t;
static inline void init_intf_nw_prop(intf_nw_props_t* intf_nw_props){
memset(intf_nw_props->mac_add.mac, 0, sizeof(intf_nw_props->mac_add.mac));
intf_nw_props->is_ipadd_config = FALSE;
memset(intf_nw_props->ip_add.ip_addr, 0, 16);
intf_nw_props->mask = 0;
}
void interface_assign_mac_address(interface_t* interface);
// Macros
#define IF_MAC(intf_ptr) ((intf_ptr)->intf_nw_props.mac_add.mac)
#define IF_IP(intf_ptr) ((intf_ptr)->intf_nw_props.ip_add.ip_addr)
#define NODE_LO_ADDR(node_ptr) (node_ptr->node_nw_prop.lb_addr.ip_addr)
//APIs to set Network Node properties
bool_t node_set_loopback_address(node_t* node, char* ip_addr);
bool_t node_set_intf_ip_address(node_t* node, char* local_if, char* ip_addr, char mask);
bool_t node_unset_intf_ip_address(node_t* node, char* local_if);
//Functions to display Nodes and Interfaces network properties
void dump_nw_graph(graph_t* graph);
void dump_node_nw_props(node_t* node);
void dump_intf_props(interface_t* interface);
#endif