90
96
if (g_str_has_prefix(name, "vboxnet") == TRUE)
99
/* virtual interface from Virtual Machine Manager */
100
if (g_str_has_prefix(name, "virbr") == TRUE)
106
static connman_bool_t wext_interface(char *ifname)
111
fd = socket(PF_INET, SOCK_DGRAM, 0);
115
memset(&wrq, 0, sizeof(wrq));
116
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
118
err = ioctl(fd, SIOCGIWNAME, &wrq);
96
128
static void read_uevent(struct interface_data *interface)
98
130
char *filename, line[128];
131
connman_bool_t found_devtype;
101
if (ether_blacklisted(interface->name) == TRUE)
102
interface->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
104
interface->type = CONNMAN_SERVICE_TYPE_ETHERNET;
134
if (ether_blacklisted(interface->name) == TRUE) {
135
interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
136
interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
138
interface->service_type = CONNMAN_SERVICE_TYPE_ETHERNET;
139
interface->device_type = CONNMAN_DEVICE_TYPE_ETHERNET;
106
142
filename = g_strdup_printf("/sys/class/net/%s/uevent",
107
143
interface->name);
124
161
if (strncmp(line, "DEVTYPE=", 8) != 0)
127
if (strcmp(line + 8, "wlan") == 0)
128
interface->type = CONNMAN_SERVICE_TYPE_WIFI;
129
else if (strcmp(line + 8, "wwan") == 0)
130
interface->type = CONNMAN_SERVICE_TYPE_CELLULAR;
131
else if (strcmp(line + 8, "bluetooth") == 0)
132
interface->type = CONNMAN_SERVICE_TYPE_BLUETOOTH;
133
else if (strcmp(line + 8, "wimax") == 0)
134
interface->type = CONNMAN_SERVICE_TYPE_WIMAX;
136
interface->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
164
found_devtype = TRUE;
166
if (strcmp(line + 8, "wlan") == 0) {
167
interface->service_type = CONNMAN_SERVICE_TYPE_WIFI;
168
interface->device_type = CONNMAN_DEVICE_TYPE_WIFI;
169
} else if (strcmp(line + 8, "wwan") == 0) {
170
interface->service_type = CONNMAN_SERVICE_TYPE_CELLULAR;
171
interface->device_type = CONNMAN_DEVICE_TYPE_CELLULAR;
172
} else if (strcmp(line + 8, "bluetooth") == 0) {
173
interface->service_type = CONNMAN_SERVICE_TYPE_BLUETOOTH;
174
interface->device_type = CONNMAN_DEVICE_TYPE_BLUETOOTH;
175
} else if (strcmp(line + 8, "wimax") == 0) {
176
interface->service_type = CONNMAN_SERVICE_TYPE_WIMAX;
177
interface->device_type = CONNMAN_DEVICE_TYPE_WIMAX;
179
interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
180
interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
189
/* We haven't got a DEVTYPE, let's check if it's a wireless device */
190
if (wext_interface(interface->name)) {
191
interface->service_type = CONNMAN_SERVICE_TYPE_WIFI;
192
interface->device_type = CONNMAN_DEVICE_TYPE_WIFI;
194
connman_error("%s runs an unsupported 802.11 driver",
143
* connman_rtnl_add_operstate_watch:
144
* @index: network device index
145
* @callback: callback function
146
* @user_data: callback data;
148
* Add a new RTNL watch for operation state events
150
* Returns: %0 on failure and a unique id on success
152
unsigned int connman_rtnl_add_operstate_watch(int index,
153
connman_rtnl_operstate_cb_t callback, void *user_data)
199
enum connman_device_type __connman_rtnl_get_device_type(int index)
155
struct watch_data *watch;
157
watch = g_try_new0(struct watch_data, 1);
161
watch->id = ++watch_id;
162
watch->index = index;
164
watch->operstate = callback;
165
watch->user_data = user_data;
167
watch_list = g_slist_prepend(watch_list, watch);
169
DBG("id %d", watch->id);
172
unsigned char operstate = 0;
175
callback(operstate, user_data);
201
struct interface_data *interface;
203
interface = g_hash_table_lookup(interface_list,
204
GINT_TO_POINTER(index));
205
if (interface == NULL)
206
return CONNMAN_DEVICE_TYPE_UNKNOWN;
208
return interface->device_type;
469
497
ifname, index, operstate,
470
498
operstate2str(operstate));
472
for (list = watch_list; list; list = list->next) {
473
struct watch_data *watch = list->data;
475
if (watch->index != index)
478
if (operstate != 0xff && watch->operstate)
479
watch->operstate(operstate, watch->user_data);
482
500
for (list = rtnl_list; list; list = list->next) {
483
501
struct connman_rtnl *rtnl = list->data;
549
static void extract_ipv6_addr(struct ifaddrmsg *msg, int bytes,
550
struct in6_addr *addr,
551
struct in6_addr *local)
555
for (attr = IFA_RTA(msg); RTA_OK(attr, bytes);
556
attr = RTA_NEXT(attr, bytes)) {
557
switch (attr->rta_type) {
560
*addr = *((struct in6_addr *) RTA_DATA(attr));
564
*local = *((struct in6_addr *) RTA_DATA(attr));
531
570
static void process_newaddr(unsigned char family, unsigned char prefixlen,
532
571
int index, struct ifaddrmsg *msg, int bytes)
534
struct in_addr address = { INADDR_ANY };
535
573
const char *label = NULL;
537
if (family != AF_INET)
540
extract_addr(msg, bytes, &label, &address, NULL, NULL);
542
__connman_ipconfig_newaddr(index, label,
543
prefixlen, inet_ntoa(address));
575
char ip_string[INET6_ADDRSTRLEN];
577
if (family != AF_INET && family != AF_INET6)
580
if (family == AF_INET) {
581
struct in_addr ipv4_addr = { INADDR_ANY };
583
extract_ipv4_addr(msg, bytes, &label, &ipv4_addr, NULL, NULL);
585
} else if (family == AF_INET6) {
586
struct in6_addr ipv6_address, ipv6_local;
588
extract_ipv6_addr(msg, bytes, &ipv6_address, &ipv6_local);
589
if (IN6_IS_ADDR_LINKLOCAL(&ipv6_address))
595
if (inet_ntop(family, src, ip_string, INET6_ADDRSTRLEN) == NULL)
598
__connman_ipconfig_newaddr(index, family, label,
599
prefixlen, ip_string);
546
602
static void process_deladdr(unsigned char family, unsigned char prefixlen,
547
603
int index, struct ifaddrmsg *msg, int bytes)
549
struct in_addr address = { INADDR_ANY };
550
605
const char *label = NULL;
552
if (family != AF_INET)
555
extract_addr(msg, bytes, &label, &address, NULL, NULL);
557
__connman_ipconfig_deladdr(index, label,
558
prefixlen, inet_ntoa(address));
607
char ip_string[INET6_ADDRSTRLEN];
609
if (family != AF_INET && family != AF_INET6)
612
if (family == AF_INET) {
613
struct in_addr ipv4_addr = { INADDR_ANY };
615
extract_ipv4_addr(msg, bytes, &label, &ipv4_addr, NULL, NULL);
617
} else if (family == AF_INET6) {
618
struct in6_addr ipv6_address, ipv6_local;
620
extract_ipv6_addr(msg, bytes, &ipv6_address, &ipv6_local);
621
if (IN6_IS_ADDR_LINKLOCAL(&ipv6_address))
627
if (inet_ntop(family, src, ip_string, INET6_ADDRSTRLEN) == NULL)
630
__connman_ipconfig_deladdr(index, family, label,
631
prefixlen, ip_string);
561
634
static void extract_route(struct rtmsg *msg, int bytes, int *index,
599
672
inet_ntop(family, &dst, dststr, sizeof(dststr));
600
673
inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
602
__connman_ipconfig_newroute(index, scope, dststr, gatewaystr);
675
__connman_ipconfig_newroute(index, family, scope, dststr, gatewaystr);
604
677
/* skip host specific routes */
605
678
if (scope != RT_SCOPE_UNIVERSE &&
633
706
inet_ntop(family, &dst, dststr, sizeof(dststr));
634
707
inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
636
__connman_ipconfig_delroute(index, scope, dststr, gatewaystr);
709
__connman_ipconfig_delroute(index, family, scope, dststr, gatewaystr);
638
711
/* skip host specific routes */
639
712
if (scope != RT_SCOPE_UNIVERSE &&