• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/netifd/tunnel.c

  1 /*
  2  * netifd - network interface daemon
  3  * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
  4  *
  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
  8  *
  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.
 13  */
 14 #include "netifd.h"
 15 #include "device.h"
 16 #include "config.h"
 17 #include "system.h"
 18 
 19 struct tunnel {
 20         struct device dev;
 21         device_state_cb set_state;
 22 };
 23 
 24 static int
 25 tunnel_set_state(struct device *dev, bool up)
 26 {
 27         struct tunnel *tun = container_of(dev, struct tunnel, dev);
 28         int ret;
 29 
 30         if (up) {
 31                 ret = system_add_ip_tunnel(dev, dev->config);
 32                 if (ret != 0)
 33                         return ret;
 34         }
 35 
 36         ret = tun->set_state(dev, up);
 37         if (ret || !up)
 38                 system_del_ip_tunnel(dev);
 39 
 40         return ret;
 41 }
 42 
 43 static enum dev_change_type
 44 tunnel_reload(struct device *dev, struct blob_attr *attr)
 45 {
 46         struct blob_attr *tb_dev[__DEV_ATTR_MAX];
 47         const struct uci_blob_param_list *cfg = dev->type->config_params;
 48 
 49         if (uci_blob_check_equal(dev->config, attr, cfg))
 50                 return DEV_CONFIG_NO_CHANGE;
 51 
 52         memset(tb_dev, 0, sizeof(tb_dev));
 53 
 54         if (attr)
 55                 blobmsg_parse_attr(device_attr_list.params, __DEV_ATTR_MAX, tb_dev, attr);
 56 
 57         device_init_settings(dev, tb_dev);
 58 
 59         return DEV_CONFIG_RESTART;
 60 }
 61 
 62 static struct device *
 63 tunnel_create(const char *name, struct device_type *devtype,
 64         struct blob_attr *attr)
 65 {
 66         struct tunnel *tun;
 67         struct device *dev;
 68 
 69         tun = calloc(1, sizeof(*tun));
 70         if (!tun)
 71                 return NULL;
 72 
 73         dev = &tun->dev;
 74 
 75         if (device_init(dev, devtype, name) < 0) {
 76                 device_cleanup(dev);
 77                 free(tun);
 78                 return NULL;
 79         }
 80 
 81         tun->set_state = dev->set_state;
 82         dev->set_state = tunnel_set_state;
 83         device_apply_config(dev, devtype, attr);
 84         device_set_present(dev, true);
 85 
 86         return dev;
 87 }
 88 
 89 static void
 90 tunnel_free(struct device *dev)
 91 {
 92         struct tunnel *tun = container_of(dev, struct tunnel, dev);
 93 
 94         free(tun);
 95 }
 96 
 97 struct device_type tunnel_device_type = {
 98         .name = "tunnel",
 99         .config_params = &tunnel_attr_list,
100         .reload = tunnel_reload,
101         .create = tunnel_create,
102         .free = tunnel_free,
103 };
104 
105 static void __init tunnel_device_type_init(void)
106 {
107         device_type_add(&tunnel_device_type);
108 }
109 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt