Fix parsing of netlink messages for routing
[connman] / plugins / 80203.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdio.h>
27 #include <arpa/inet.h>
28
29 #include <connman/plugin.h>
30 #include <connman/iface.h>
31
32 #include "net.h"
33
34 static int iface_probe(struct connman_iface *iface)
35 {
36         printf("[802.03] probe interface index %d\n", iface->index);
37
38         iface->type = CONNMAN_IFACE_TYPE_80203;
39
40         iface->flags = CONNMAN_IFACE_FLAG_RTNL |
41                                 CONNMAN_IFACE_FLAG_IPV4 |
42                                 CONNMAN_IFACE_FLAG_CARRIER_DETECT;
43
44         return 0;
45 }
46
47 static void iface_remove(struct connman_iface *iface)
48 {
49         printf("[802.03] remove interface index %d\n", iface->index);
50
51         __net_clear(iface->index);
52 }
53
54 static int iface_get_ipv4(struct connman_iface *iface,
55                                         struct connman_ipv4 *ipv4)
56 {
57         if (__net_ifaddr(iface->index, &ipv4->address) < 0)
58                 return -1;
59
60         printf("[802.03] get address %s\n", inet_ntoa(ipv4->address));
61
62         return 0;
63 }
64
65 static int iface_set_ipv4(struct connman_iface *iface,
66                                         struct connman_ipv4 *ipv4)
67 {
68         printf("[802.03] set address %s\n", inet_ntoa(ipv4->address));
69         printf("[802.03] set netmask %s\n", inet_ntoa(ipv4->netmask));
70         printf("[802.03] set gateway %s\n", inet_ntoa(ipv4->gateway));
71
72         __net_set(iface->index, &ipv4->address, &ipv4->netmask,
73                                 &ipv4->gateway, &ipv4->broadcast,
74                                                 &ipv4->nameserver);
75
76         return 0;
77 }
78
79 static struct connman_iface_driver iface_driver = {
80         .name           = "80203",
81         .capability     = "net.80203",
82         .probe          = iface_probe,
83         .remove         = iface_remove,
84         .get_ipv4       = iface_get_ipv4,
85         .set_ipv4       = iface_set_ipv4,
86 };
87
88 static int plugin_init(void)
89 {
90         connman_iface_register(&iface_driver);
91
92         return 0;
93 }
94
95 static void plugin_exit(void)
96 {
97         connman_iface_unregister(&iface_driver);
98 }
99
100 CONNMAN_PLUGIN_DEFINE("80203", "IEEE 802.03 interface plugin", VERSION,
101                                                 plugin_init, plugin_exit)