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.
21 device_state_cb set_state
;
25 tunnel_set_state(struct device
*dev
, bool up
)
27 struct tunnel
*tun
= container_of(dev
, struct tunnel
, dev
);
31 ret
= system_add_ip_tunnel(dev
->ifname
, dev
->config
);
36 ret
= tun
->set_state(dev
, up
);
38 system_del_ip_tunnel(dev
->ifname
, dev
->config
);
43 static enum dev_change_type
44 tunnel_reload(struct device
*dev
, struct blob_attr
*attr
)
46 struct blob_attr
*tb_dev
[__DEV_ATTR_MAX
];
47 const struct uci_blob_param_list
*cfg
= dev
->type
->config_params
;
49 if (uci_blob_check_equal(dev
->config
, attr
, cfg
))
50 return DEV_CONFIG_NO_CHANGE
;
52 memset(tb_dev
, 0, sizeof(tb_dev
));
55 blobmsg_parse(device_attr_list
.params
, __DEV_ATTR_MAX
, tb_dev
,
56 blob_data(attr
), blob_len(attr
));
58 device_init_settings(dev
, tb_dev
);
60 return DEV_CONFIG_RESTART
;
63 static struct device
*
64 tunnel_create(const char *name
, struct device_type
*devtype
,
65 struct blob_attr
*attr
)
70 tun
= calloc(1, sizeof(*tun
));
76 if (device_init(dev
, devtype
, name
) < 0) {
82 tun
->set_state
= dev
->set_state
;
83 dev
->set_state
= tunnel_set_state
;
84 device_apply_config(dev
, devtype
, attr
);
85 device_set_present(dev
, true);
91 tunnel_free(struct device
*dev
)
93 struct tunnel
*tun
= container_of(dev
, struct tunnel
, dev
);
98 struct device_type tunnel_device_type
= {
100 .config_params
= &tunnel_attr_list
,
101 .reload
= tunnel_reload
,
102 .create
= tunnel_create
,
106 static void __init
tunnel_device_type_init(void)
108 device_type_add(&tunnel_device_type
);