blob: b16600ce749ab06ed2bbce301faddc99049d4d5a (
plain)
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
|
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "netifd.h"
#include "interface.h"
#include "proto.h"
static void
default_proto_free(struct interface_proto_state *proto)
{
free(proto);
}
static int
default_proto_handler(struct interface_proto_state *proto,
enum interface_proto_cmd cmd, bool force)
{
return 0;
}
struct interface_proto_state *get_default_proto(void)
{
struct interface_proto_state *proto;
proto = calloc(1, sizeof(*proto));
proto->handler = default_proto_handler;
proto->free = default_proto_free;
proto->flags = PROTO_FLAG_IMMEDIATE;
return proto;
}
int interface_proto_event(struct interface_proto_state *proto,
enum interface_proto_cmd cmd, bool force)
{
enum interface_event ev;
int ret;
ret = proto->handler(proto, cmd, force);
if (ret || !(proto->flags & PROTO_FLAG_IMMEDIATE))
goto out;
switch(cmd) {
case PROTO_CMD_SETUP:
ev = IFEV_UP;
break;
case PROTO_CMD_TEARDOWN:
ev = IFEV_DOWN;
break;
default:
return -EINVAL;
}
proto->proto_event(proto, ev);
out:
return ret;
}
|