2 * netifd - network interface daemon
3 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
18 #include <arpa/inet.h>
19 #include <netinet/in.h>
22 #include "interface.h"
23 #include "interface-ip.h"
27 struct static_proto_state {
28 struct interface_proto_state proto;
30 struct blob_attr *config;
34 static_proto_setup(struct static_proto_state *state)
36 struct interface *iface = state->proto.iface;
37 struct device *dev = iface->main_dev.dev;
39 interface_set_l3_dev(iface, dev);
40 return proto_apply_static_ip_settings(state->proto.iface, state->config) == 0;
44 static_handler(struct interface_proto_state *proto,
45 enum interface_proto_cmd cmd, bool force)
47 struct static_proto_state *state;
50 state = container_of(proto, struct static_proto_state, proto);
54 if (!static_proto_setup(state))
58 case PROTO_CMD_TEARDOWN:
67 static_free(struct interface_proto_state *proto)
69 struct static_proto_state *state;
71 state = container_of(proto, struct static_proto_state, proto);
76 static struct interface_proto_state *
77 static_attach(const struct proto_handler *h, struct interface *iface,
78 struct blob_attr *attr)
80 struct static_proto_state *state;
82 state = calloc(1, sizeof(*state));
86 state->config = malloc(blob_pad_len(attr));
90 memcpy(state->config, attr, blob_pad_len(attr));
91 state->proto.free = static_free;
92 state->proto.cb = static_handler;
101 static struct proto_handler static_proto = {
103 .flags = PROTO_FLAG_IMMEDIATE |
104 PROTO_FLAG_FORCE_LINK_DEFAULT,
105 .config_params = &proto_ip_attr,
106 .attach = static_attach,
110 static_proto_init(void)
112 add_proto_handler(&static_proto);