~connman-maintainers/connman/head

« back to all changes in this revision

Viewing changes to src/dnsproxy.c

  • Committer: Patrik Flykt
  • Author(s): Daniel Wagner
  • Date: 2013-08-07 06:46:54 UTC
  • Revision ID: git-v1:bd99aaa74d1c627d43353ed0ae77b72e1e2bc8e6
core: Do not compare expression against NULL

This patch generate via coccinelle with:

@ disable is_null,isnt_null1 @
expression E;
@@

(
- E == NULL
+ !E
|
- E != NULL
+ E
)

Show diffs side-by-side

added added

removed removed

Lines of Context:
288
288
                        return data;
289
289
 
290
290
                if (index < 0 ||
291
 
                                data->index < 0 || data->server == NULL)
 
291
                                data->index < 0 || !data->server)
292
292
                        continue;
293
293
 
294
294
                if (data->index == index &&
315
315
{
316
316
        int age = 1;
317
317
 
318
 
        if (ipv4_resolve == NULL) {
 
318
        if (!ipv4_resolve) {
319
319
                ipv4_resolve = g_resolv_new(0);
320
320
                g_resolv_set_address_family(ipv4_resolve, AF_INET);
321
321
                g_resolv_add_nameserver(ipv4_resolve, "127.0.0.1", 53, 0);
322
322
        }
323
323
 
324
 
        if (ipv6_resolve == NULL) {
 
324
        if (!ipv6_resolve) {
325
325
                ipv6_resolve = g_resolv_new(0);
326
326
                g_resolv_set_address_family(ipv6_resolve, AF_INET6);
327
327
                g_resolv_add_nameserver(ipv6_resolve, "::1", 53, 0);
328
328
        }
329
329
 
330
 
        if (entry->ipv4 == NULL) {
 
330
        if (!entry->ipv4) {
331
331
                DBG("Refresing A record for %s", name);
332
332
                g_resolv_lookup_hostname(ipv4_resolve, name,
333
333
                                        dummy_resolve_func, NULL);
334
334
                age = 4;
335
335
        }
336
336
 
337
 
        if (entry->ipv6 == NULL) {
 
337
        if (!entry->ipv6) {
338
338
                DBG("Refresing AAAA record for %s", name);
339
339
                g_resolv_lookup_hostname(ipv6_resolve, name,
340
340
                                        dummy_resolve_func, NULL);
505
505
        else
506
506
                channel = req->ifdata->udp6_listener_channel;
507
507
 
508
 
        if (channel == NULL)
 
508
        if (!channel)
509
509
                return -1;
510
510
 
511
511
        return g_io_channel_unix_get_fd(channel);
526
526
{
527
527
        struct request_data *req = user_data;
528
528
 
529
 
        if (req == NULL)
 
529
        if (!req)
530
530
                return FALSE;
531
531
 
532
532
        DBG("id 0x%04x", req->srcid);
534
534
        request_list = g_slist_remove(request_list, req);
535
535
        req->numserv--;
536
536
 
537
 
        if (req->resplen > 0 && req->resp != NULL) {
 
537
        if (req->resplen > 0 && req->resp) {
538
538
                int sk, err;
539
539
 
540
540
                if (req->protocol == IPPROTO_UDP) {
599
599
 
600
600
        DBG("query %s domain %s", query, domain);
601
601
 
602
 
        while (query != NULL) {
 
602
        while (query) {
603
603
                const char *tmp;
604
604
 
605
605
                tmp = strchr(query, '.');
606
 
                if (tmp == NULL) {
 
606
                if (!tmp) {
607
607
                        len = strlen(query);
608
608
                        if (len == 0)
609
609
                                break;
620
620
                query = tmp + 1;
621
621
        }
622
622
 
623
 
        while (domain != NULL) {
 
623
        while (domain) {
624
624
                const char *tmp;
625
625
 
626
626
                tmp = strchr(domain, '.');
627
 
                if (tmp == NULL) {
 
627
                if (!tmp) {
628
628
                        len = strlen(domain);
629
629
                        if (len == 0)
630
630
                                break;
649
649
static bool cache_check_is_valid(struct cache_data *data,
650
650
                                time_t current_time)
651
651
{
652
 
        if (data == NULL)
 
652
        if (!data)
653
653
                return false;
654
654
 
655
655
        if (data->cache_until < current_time)
741
741
{
742
742
        struct cache_entry *entry = value;
743
743
 
744
 
        if (entry == NULL)
 
744
        if (!entry)
745
745
                return;
746
746
 
747
 
        if (entry->ipv4 != NULL) {
 
747
        if (entry->ipv4) {
748
748
                g_free(entry->ipv4->data);
749
749
                g_free(entry->ipv4);
750
750
        }
751
751
 
752
 
        if (entry->ipv6 != NULL) {
 
752
        if (entry->ipv6) {
753
753
                g_free(entry->ipv6->data);
754
754
                g_free(entry->ipv6);
755
755
        }
790
790
        uint16_t type;
791
791
        int offset, proto_offset;
792
792
 
793
 
        if (request == NULL)
 
793
        if (!request)
794
794
                return NULL;
795
795
 
796
796
        proto_offset = protocol_offset(proto);
807
807
        if (type != 1 && type != 28)
808
808
                return NULL;
809
809
 
810
 
        if (cache == NULL) {
 
810
        if (!cache) {
811
811
                create_cache();
812
812
                return NULL;
813
813
        }
814
814
 
815
815
        entry = g_hash_table_lookup(cache, question);
816
 
        if (entry == NULL)
 
816
        if (!entry)
817
817
                return NULL;
818
818
 
819
819
        type = cache_check_validity(question, type, entry);
850
850
                        if (offset >= max - pkt)
851
851
                                return -ENOBUFS;
852
852
 
853
 
                        if (*end == NULL)
 
853
                        if (!*end)
854
854
                                *end = p + 2;
855
855
 
856
856
                        return get_name(counter + 1, pkt, pkt + offset, max,
880
880
 
881
881
                        p += label_len + 1;
882
882
 
883
 
                        if (*end == NULL)
 
883
                        if (!*end)
884
884
                                *end = p;
885
885
 
886
886
                        if (p >= max)
914
914
 
915
915
        rr = (void *) (*end);
916
916
 
917
 
        if (rr == NULL)
 
917
        if (!rr)
918
918
                return -EINVAL;
919
919
 
920
920
        *type = ntohs(rr->type);
946
946
{
947
947
        GSList *list;
948
948
 
949
 
        if (aliases != NULL) {
 
949
        if (aliases) {
950
950
                for (list = aliases; list; list = list->next) {
951
951
                        int len = strlen((char *)list->data);
952
952
                        if (strncmp((char *)list->data, name, len) == 0)
1119
1119
                         * We found correct type (A or AAAA)
1120
1120
                         */
1121
1121
                        if (check_alias(aliases, name) ||
1122
 
                                (aliases == NULL && strncmp(question, name,
 
1122
                                (!aliases && strncmp(question, name,
1123
1123
                                                        qlen) == 0)) {
1124
1124
                                /*
1125
1125
                                 * We found an alias or the name of the rr
1174
1174
         * remove both from the cache.
1175
1175
         */
1176
1176
 
1177
 
        if (entry->ipv4 != NULL && entry->ipv4->timeout > 0) {
 
1177
        if (entry->ipv4 && entry->ipv4->timeout > 0) {
1178
1178
                max_timeout = entry->ipv4->cache_until;
1179
1179
                if (max_timeout > data->max_timeout)
1180
1180
                        data->max_timeout = max_timeout;
1183
1183
                        return TRUE;
1184
1184
        }
1185
1185
 
1186
 
        if (entry->ipv6 != NULL && entry->ipv6->timeout > 0) {
 
1186
        if (entry->ipv6 && entry->ipv6->timeout > 0) {
1187
1187
                max_timeout = entry->ipv6->cache_until;
1188
1188
                if (max_timeout > data->max_timeout)
1189
1189
                        data->max_timeout = max_timeout;
1287
1287
{
1288
1288
        DBG("Invalidating the DNS cache %p", cache);
1289
1289
 
1290
 
        if (cache == NULL)
 
1290
        if (!cache)
1291
1291
                return;
1292
1292
 
1293
1293
        g_hash_table_foreach_remove(cache, cache_invalidate_entry, NULL);
1298
1298
 
1299
1299
        cache_enforce_validity(entry);
1300
1300
 
1301
 
        if (entry->hits > 2 && entry->ipv4 == NULL)
 
1301
        if (entry->hits > 2 && !entry->ipv4)
1302
1302
                entry->want_refresh = true;
1303
 
        if (entry->hits > 2 && entry->ipv6 == NULL)
 
1303
        if (entry->hits > 2 && !entry->ipv6)
1304
1304
                entry->want_refresh = true;
1305
1305
 
1306
1306
        if (entry->want_refresh) {
1333
1333
 
1334
1334
static void cache_refresh(void)
1335
1335
{
1336
 
        if (cache == NULL)
 
1336
        if (!cache)
1337
1337
                return;
1338
1338
 
1339
1339
        g_hash_table_foreach(cache, cache_refresh_iterator, NULL);
1418
1418
        if ((err == -ENOMSG || err == -ENOBUFS) &&
1419
1419
                        reply_query_type(msg + offset,
1420
1420
                                        msg_len - offset) == 28) {
1421
 
                if (cache == NULL) {
 
1421
                if (!cache) {
1422
1422
                        create_cache();
1423
1423
                        entry = NULL;
1424
1424
                } else
1425
1425
                        entry = g_hash_table_lookup(cache, question);
1426
 
                if (entry && entry->ipv4 && entry->ipv6 == NULL) {
 
1426
                if (entry && entry->ipv4 && !entry->ipv6) {
1427
1427
                        int cache_offset = 0;
1428
1428
 
1429
1429
                        data = g_try_new(struct cache_data, 1);
1430
 
                        if (data == NULL)
 
1430
                        if (!data)
1431
1431
                                return -ENOMEM;
1432
1432
                        data->inserted = entry->ipv4->inserted;
1433
1433
                        data->type = type;
1469
1469
         * records for the same name.
1470
1470
         */
1471
1471
        entry = g_hash_table_lookup(cache, question);
1472
 
        if (entry == NULL) {
 
1472
        if (!entry) {
1473
1473
                entry = g_try_new(struct cache_entry, 1);
1474
 
                if (entry == NULL)
 
1474
                if (!entry)
1475
1475
                        return -ENOMEM;
1476
1476
 
1477
1477
                data = g_try_new(struct cache_data, 1);
1478
 
                if (data == NULL) {
 
1478
                if (!data) {
1479
1479
                        g_free(entry);
1480
1480
                        return -ENOMEM;
1481
1481
                }
1490
1490
                else
1491
1491
                        entry->ipv6 = data;
1492
1492
        } else {
1493
 
                if (type == 1 && entry->ipv4 != NULL)
 
1493
                if (type == 1 && entry->ipv4)
1494
1494
                        return 0;
1495
1495
 
1496
 
                if (type == 28 && entry->ipv6 != NULL)
 
1496
                if (type == 28 && entry->ipv6)
1497
1497
                        return 0;
1498
1498
 
1499
1499
                data = g_try_new(struct cache_data, 1);
1500
 
                if (data == NULL)
 
1500
                if (!data)
1501
1501
                        return -ENOMEM;
1502
1502
 
1503
1503
                if (type == 1)
1541
1541
 
1542
1542
        data->cache_until = round_down_ttl(current_time + ttl, ttl);
1543
1543
 
1544
 
        if (data->data == NULL) {
 
1544
        if (!data->data) {
1545
1545
                g_free(entry->key);
1546
1546
                g_free(data);
1547
1547
                g_free(entry);
1599
1599
        struct cache_entry *entry;
1600
1600
 
1601
1601
        entry = cache_check(request, &type, req->protocol);
1602
 
        if (entry != NULL) {
 
1602
        if (entry) {
1603
1603
                int ttl_left = 0;
1604
1604
                struct cache_data *data;
1605
1605
 
1614
1614
                        entry->hits++;
1615
1615
                }
1616
1616
 
1617
 
                if (data != NULL && req->protocol == IPPROTO_TCP) {
 
1617
                if (data && req->protocol == IPPROTO_TCP) {
1618
1618
                        send_cached_response(req->client_sk, data->data,
1619
1619
                                        data->data_len, NULL, 0, IPPROTO_TCP,
1620
1620
                                        req->srcid, data->answers, ttl_left);
1621
1621
                        return 1;
1622
1622
                }
1623
1623
 
1624
 
                if (data != NULL && req->protocol == IPPROTO_UDP) {
 
1624
                if (data && req->protocol == IPPROTO_UDP) {
1625
1625
                        int udp_sk = get_req_udp_socket(req);
1626
1626
 
1627
1627
                        send_cached_response(udp_sk, data->data,
1648
1648
 
1649
1649
        /* If we have more than one dot, we don't add domains */
1650
1650
        dot = strchr(lookup, '.');
1651
 
        if (dot != NULL && dot != lookup + strlen(lookup) - 1)
 
1651
        if (dot && dot != lookup + strlen(lookup) - 1)
1652
1652
                return 0;
1653
1653
 
1654
 
        if (server->domains != NULL && server->domains->data != NULL)
 
1654
        if (server->domains && server->domains->data)
1655
1655
                req->append_domain = true;
1656
1656
 
1657
1657
        for (list = server->domains; list; list = list->next) {
1662
1662
 
1663
1663
                domain = list->data;
1664
1664
 
1665
 
                if (domain == NULL)
 
1665
                if (!domain)
1666
1666
                        continue;
1667
1667
 
1668
1668
                offset = protocol_offset(server->protocol);
1726
1726
        DBG("Received %d bytes (id 0x%04x)", reply_len, dns_id);
1727
1727
 
1728
1728
        req = find_request(dns_id);
1729
 
        if (req == NULL)
 
1729
        if (!req)
1730
1730
                return -EINVAL;
1731
1731
 
1732
1732
        DBG("req %p dstid 0x%04x altid 0x%04x rcode %d",
1737
1737
 
1738
1738
        req->numresp++;
1739
1739
 
1740
 
        if (hdr->rcode == 0 || req->resp == NULL) {
 
1740
        if (hdr->rcode == 0 || !req->resp) {
1741
1741
 
1742
1742
                /*
1743
1743
                 * If the domain name was append
1792
1792
                req->resplen = 0;
1793
1793
 
1794
1794
                req->resp = g_try_malloc(reply_len);
1795
 
                if (req->resp == NULL)
 
1795
                if (!req->resp)
1796
1796
                        return -ENOMEM;
1797
1797
 
1798
1798
                memcpy(req->resp, reply, reply_len);
1841
1841
                data->timeout = 0;
1842
1842
        }
1843
1843
 
1844
 
        if (data->channel != NULL) {
 
1844
        if (data->channel) {
1845
1845
                g_io_channel_shutdown(data->channel, TRUE, NULL);
1846
1846
                g_io_channel_unref(data->channel);
1847
1847
                data->channel = NULL;
1943
1943
                        if (req->protocol == IPPROTO_UDP)
1944
1944
                                continue;
1945
1945
 
1946
 
                        if (req->request == NULL)
 
1946
                        if (!req->request)
1947
1947
                                continue;
1948
1948
 
1949
1949
                        /*
1975
1975
 
1976
1976
                udp_server = find_server(server->index, server->server,
1977
1977
                                                                IPPROTO_UDP);
1978
 
                if (udp_server != NULL) {
 
1978
                if (udp_server) {
1979
1979
                        for (domains = udp_server->domains; domains;
1980
1980
                                                domains = domains->next) {
1981
1981
                                char *dom = domains->data;
2113
2113
 
2114
2114
        DBG("");
2115
2115
 
2116
 
        if (server == NULL)
 
2116
        if (!server)
2117
2117
                return FALSE;
2118
2118
 
2119
2119
        destroy_server(server);
2143
2143
        DBG("sk %d", sk);
2144
2144
 
2145
2145
        interface = connman_inet_ifname(data->index);
2146
 
        if (interface != NULL) {
 
2146
        if (interface) {
2147
2147
                if (setsockopt(sk, SOL_SOCKET, SO_BINDTODEVICE,
2148
2148
                                        interface,
2149
2149
                                        strlen(interface) + 1) < 0) {
2160
2160
        }
2161
2161
 
2162
2162
        data->channel = g_io_channel_unix_new(sk);
2163
 
        if (data->channel == NULL) {
 
2163
        if (!data->channel) {
2164
2164
                connman_error("Failed to create server %s channel",
2165
2165
                                                        data->server);
2166
2166
                close(sk);
2211
2211
        DBG("index %d server %s", index, server);
2212
2212
 
2213
2213
        data = g_try_new0(struct server_data, 1);
2214
 
        if (data == NULL) {
 
2214
        if (!data) {
2215
2215
                connman_error("Failed to allocate server %s data", server);
2216
2216
                return NULL;
2217
2217
        }
2267
2267
                connman_error("Wrong address family %d", rp->ai_family);
2268
2268
                break;
2269
2269
        }
2270
 
        if (data->server_addr == NULL) {
 
2270
        if (!data->server_addr) {
2271
2271
                freeaddrinfo(rp);
2272
2272
                destroy_server(data);
2273
2273
                return NULL;
2309
2309
                if (!data->enabled)
2310
2310
                        continue;
2311
2311
 
2312
 
                if (data->channel == NULL && data->protocol == IPPROTO_UDP) {
 
2312
                if (!data->channel && data->protocol == IPPROTO_UDP) {
2313
2313
                        if (server_create_socket(data) < 0) {
2314
2314
                                DBG("socket creation failed while resolving");
2315
2315
                                continue;
2329
2329
 
2330
2330
        DBG("index %d domain %s", index, domain);
2331
2331
 
2332
 
        if (domain == NULL)
 
2332
        if (!domain)
2333
2333
                return;
2334
2334
 
2335
2335
        for (list = server_list; list; list = list->next) {
2368
2368
 
2369
2369
        DBG("index %d server %s", index, server);
2370
2370
 
2371
 
        if (server == NULL && domain == NULL)
 
2371
        if (!server && !domain)
2372
2372
                return -EINVAL;
2373
2373
 
2374
 
        if (server == NULL) {
 
2374
        if (!server) {
2375
2375
                append_domain(index, domain);
2376
2376
 
2377
2377
                return 0;
2384
2384
                return -ENODEV;
2385
2385
 
2386
2386
        data = find_server(index, server, IPPROTO_UDP);
2387
 
        if (data != NULL) {
 
2387
        if (data) {
2388
2388
                append_domain(index, domain);
2389
2389
                return 0;
2390
2390
        }
2391
2391
 
2392
2392
        data = create_server(index, domain, server, IPPROTO_UDP);
2393
 
        if (data == NULL)
 
2393
        if (!data)
2394
2394
                return -EIO;
2395
2395
 
2396
2396
        return 0;
2402
2402
        struct server_data *data;
2403
2403
 
2404
2404
        data = find_server(index, server, protocol);
2405
 
        if (data == NULL)
 
2405
        if (!data)
2406
2406
                return;
2407
2407
 
2408
2408
        destroy_server(data);
2413
2413
{
2414
2414
        DBG("index %d server %s", index, server);
2415
2415
 
2416
 
        if (server == NULL)
 
2416
        if (!server)
2417
2417
                return -EINVAL;
2418
2418
 
2419
2419
        if (g_str_equal(server, "127.0.0.1"))
2487
2487
        /* DNS has changed, invalidate the cache */
2488
2488
        cache_invalidate();
2489
2489
 
2490
 
        if (service == NULL) {
 
2490
        if (!service) {
2491
2491
                /* When no services are active, then disable DNS proxying */
2492
2492
                dnsproxy_offline_mode(true);
2493
2493
                return;
2594
2594
 
2595
2595
static void client_reset(struct tcp_partial_client_data *client)
2596
2596
{
2597
 
        if (client == NULL)
 
2597
        if (!client)
2598
2598
                return;
2599
2599
 
2600
 
        if (client->channel != NULL) {
 
2600
        if (client->channel) {
2601
2601
                DBG("client %d closing",
2602
2602
                        g_io_channel_unix_get_fd(client->channel));
2603
2603
 
2686
2686
        }
2687
2687
 
2688
2688
        req = g_try_new0(struct request_data, 1);
2689
 
        if (req == NULL)
 
2689
        if (!req)
2690
2690
                return true;
2691
2691
 
2692
2692
        memcpy(&req->sa, client_addr, client_addr_len);
2712
2712
         * creating sockets to the server.
2713
2713
         */
2714
2714
        entry = cache_check(client->buf, &qtype, IPPROTO_TCP);
2715
 
        if (entry != NULL) {
 
2715
        if (entry) {
2716
2716
                int ttl_left = 0;
2717
2717
                struct cache_data *data;
2718
2718
 
2722
2722
                else
2723
2723
                        data = entry->ipv6;
2724
2724
 
2725
 
                if (data != NULL) {
 
2725
                if (data) {
2726
2726
                        ttl_left = data->valid_until - time(NULL);
2727
2727
                        entry->hits++;
2728
2728
 
2742
2742
                if (data->protocol != IPPROTO_UDP || !data->enabled)
2743
2743
                        continue;
2744
2744
 
2745
 
                if(create_server(data->index, NULL,
2746
 
                                        data->server, IPPROTO_TCP) == NULL)
 
2745
                if(!create_server(data->index, NULL, data->server, IPPROTO_TCP))
2747
2746
                        continue;
2748
2747
 
2749
2748
                waiting_for_connect = true;
2764
2763
         * properly connected over TCP to the nameserver.
2765
2764
         */
2766
2765
        req->request = g_try_malloc0(req->request_len);
2767
 
        if (req->request == NULL) {
 
2766
        if (!req->request) {
2768
2767
                send_response(client_sk, client->buf,
2769
2768
                        req->request_len, NULL, 0, IPPROTO_TCP);
2770
2769
                g_free(req);
2773
2772
        memcpy(req->request, client->buf, req->request_len);
2774
2773
 
2775
2774
        req->name = g_try_malloc0(sizeof(query));
2776
 
        if (req->name == NULL) {
 
2775
        if (!req->name) {
2777
2776
                send_response(client_sk, client->buf,
2778
2777
                        req->request_len, NULL, 0, IPPROTO_TCP);
2779
2778
                g_free(req->request);
2957
2956
 
2958
2957
        client = g_hash_table_lookup(partial_tcp_req_table,
2959
2958
                                        GINT_TO_POINTER(client_sk));
2960
 
        if (client == NULL) {
 
2959
        if (!client) {
2961
2960
                client = g_try_new0(struct tcp_partial_client_data, 1);
2962
 
                if (client == NULL) {
 
2961
                if (!client) {
2963
2962
                        close(client_sk);
2964
2963
                        return false;
2965
2964
                }
2982
2981
                DBG("client %d already exists %p", client_sk, client);
2983
2982
        }
2984
2983
 
2985
 
        if (client->buf == NULL) {
 
2984
        if (!client->buf) {
2986
2985
                client->buf = g_try_malloc(TCP_MAX_BUF_LEN);
2987
 
                if (client->buf == NULL)
 
2986
                if (!client->buf)
2988
2987
                        return false;
2989
2988
        }
2990
2989
        memset(client->buf, 0, TCP_MAX_BUF_LEN);
3108
3107
        }
3109
3108
 
3110
3109
        req = g_try_new0(struct request_data, 1);
3111
 
        if (req == NULL)
 
3110
        if (!req)
3112
3111
                return true;
3113
3112
 
3114
3113
        memcpy(&req->sa, client_addr, *client_addr_len);
3201
3200
        }
3202
3201
 
3203
3202
        interface = connman_inet_ifname(index);
3204
 
        if (interface == NULL || setsockopt(sk, SOL_SOCKET, SO_BINDTODEVICE,
 
3203
        if (!interface || setsockopt(sk, SOL_SOCKET, SO_BINDTODEVICE,
3205
3204
                                        interface,
3206
3205
                                        strlen(interface) + 1) < 0) {
3207
3206
                connman_error("Failed to bind %s listener interface "
3267
3266
        }
3268
3267
 
3269
3268
        channel = g_io_channel_unix_new(sk);
3270
 
        if (channel == NULL) {
 
3269
        if (!channel) {
3271
3270
                connman_error("Failed to create %s listener channel", proto);
3272
3271
                close(sk);
3273
3272
                return NULL;
3294
3293
        if (protocol == IPPROTO_TCP) {
3295
3294
                ifdata->tcp4_listener_channel = get_listener(AF_INET, protocol,
3296
3295
                                                        ifdata->index);
3297
 
                if (ifdata->tcp4_listener_channel != NULL)
 
3296
                if (ifdata->tcp4_listener_channel)
3298
3297
                        ifdata->tcp4_listener_watch =
3299
3298
                                g_io_add_watch(ifdata->tcp4_listener_channel,
3300
3299
                                        G_IO_IN, tcp4_listener_event,
3304
3303
 
3305
3304
                ifdata->tcp6_listener_channel = get_listener(AF_INET6, protocol,
3306
3305
                                                        ifdata->index);
3307
 
                if (ifdata->tcp6_listener_channel != NULL)
 
3306
                if (ifdata->tcp6_listener_channel)
3308
3307
                        ifdata->tcp6_listener_watch =
3309
3308
                                g_io_add_watch(ifdata->tcp6_listener_channel,
3310
3309
                                        G_IO_IN, tcp6_listener_event,
3314
3313
        } else {
3315
3314
                ifdata->udp4_listener_channel = get_listener(AF_INET, protocol,
3316
3315
                                                        ifdata->index);
3317
 
                if (ifdata->udp4_listener_channel != NULL)
 
3316
                if (ifdata->udp4_listener_channel)
3318
3317
                        ifdata->udp4_listener_watch =
3319
3318
                                g_io_add_watch(ifdata->udp4_listener_channel,
3320
3319
                                        G_IO_IN, udp4_listener_event,
3324
3323
 
3325
3324
                ifdata->udp6_listener_channel = get_listener(AF_INET6, protocol,
3326
3325
                                                        ifdata->index);
3327
 
                if (ifdata->udp6_listener_channel != NULL)
 
3326
                if (ifdata->udp6_listener_channel)
3328
3327
                        ifdata->udp6_listener_watch =
3329
3328
                                g_io_add_watch(ifdata->udp6_listener_channel,
3330
3329
                                        G_IO_IN, udp6_listener_event,
3346
3345
        if (ifdata->udp6_listener_watch > 0)
3347
3346
                g_source_remove(ifdata->udp6_listener_watch);
3348
3347
 
3349
 
        if (ifdata->udp4_listener_channel != NULL)
 
3348
        if (ifdata->udp4_listener_channel)
3350
3349
                g_io_channel_unref(ifdata->udp4_listener_channel);
3351
 
        if (ifdata->udp6_listener_channel != NULL)
 
3350
        if (ifdata->udp6_listener_channel)
3352
3351
                g_io_channel_unref(ifdata->udp6_listener_channel);
3353
3352
}
3354
3353
 
3361
3360
        if (ifdata->tcp6_listener_watch > 0)
3362
3361
                g_source_remove(ifdata->tcp6_listener_watch);
3363
3362
 
3364
 
        if (ifdata->tcp4_listener_channel != NULL)
 
3363
        if (ifdata->tcp4_listener_channel)
3365
3364
                g_io_channel_unref(ifdata->tcp4_listener_channel);
3366
 
        if (ifdata->tcp6_listener_channel != NULL)
 
3365
        if (ifdata->tcp6_listener_channel)
3367
3366
                g_io_channel_unref(ifdata->tcp6_listener_channel);
3368
3367
}
3369
3368
 
3430
3429
        if (index < 0)
3431
3430
                return -EINVAL;
3432
3431
 
3433
 
        if (listener_table == NULL)
 
3432
        if (!listener_table)
3434
3433
                return -ENOENT;
3435
3434
 
3436
 
        if (g_hash_table_lookup(listener_table, GINT_TO_POINTER(index)) != NULL)
 
3435
        if (g_hash_table_lookup(listener_table, GINT_TO_POINTER(index)))
3437
3436
                return 0;
3438
3437
 
3439
3438
        ifdata = g_try_new0(struct listener_data, 1);
3440
 
        if (ifdata == NULL)
 
3439
        if (!ifdata)
3441
3440
                return -ENOMEM;
3442
3441
 
3443
3442
        ifdata->index = index;
3468
3467
 
3469
3468
        DBG("index %d", index);
3470
3469
 
3471
 
        if (listener_table == NULL)
 
3470
        if (!listener_table)
3472
3471
                return;
3473
3472
 
3474
3473
        ifdata = g_hash_table_lookup(listener_table, GINT_TO_POINTER(index));
3475
 
        if (ifdata == NULL)
 
3474
        if (!ifdata)
3476
3475
                return;
3477
3476
 
3478
3477
        destroy_listener(ifdata);