forked from sorindumitru/lkl-net
-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface.c
executable file
·45 lines (37 loc) · 1.06 KB
/
interface.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
#include <stdlib.h>
#include <stdio.h>
#include <interface.h>
#include <asm/env.h>
#include <asm/eth.h>
interface_t* alloc_interface()
{
interface_t* interface = malloc(sizeof(interface_t));
interface->address.s_addr = 0;
return interface;
}
int lkl_init_interface(const interface_t* interface)
{
int ifindex;
struct tun_device* td = malloc(sizeof(*td));
/* TODO: initializa from interface_t */
td->type = TUN_HUB;
td->port = interface->port;
td->address = interface->gateway.s_addr;
if ((ifindex=lkl_add_eth_tun(interface->dev, (char*) interface->mac, 32, td)) < 0) {
printf("LKL init :: could not bring up interface %s\n",interface->dev);
return -1;
}
if (interface->address.s_addr == 0) {
printf("LKL init :: warning! interface address not defined\n");
} else {
if (lkl_if_set_ipv4(ifindex, interface->address.s_addr, interface->netmask_len) < 0) {
printf("LKL init :: could not set IPv4 address\n");
return -1;
}
}
if (lkl_if_up(ifindex) < 0) {
printf("LKL init :: could not bring up interface\n");
return -1;
}
return ifindex;
}