-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathtunnel.c
67 lines (58 loc) · 1.74 KB
/
tunnel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* This file is a part of plotnetcfg, a tool to visualize network config.
* Copyright (C) 2014 Red Hat, Inc. -- Jiri Benc <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "tunnel.h"
#include <string.h>
#include <sys/socket.h>
#include "addr.h"
#include "if.h"
#include "match.h"
static int match_tunnel(struct if_entry *entry, void *arg)
{
struct addr *data = arg;
struct if_addr *addr;
if (!(entry->flags & IF_UP))
return 0;
list_for_each(addr, entry->addr) {
if (addr->addr.family != data->family)
continue;
if (!memcmp(addr->addr.raw, data->raw, data->family == AF_INET ? 4 : 16))
return 1;
}
return 0;
}
struct if_entry *tunnel_find_str(struct netns_entry *ns, const char *addr)
{
struct addr data;
char buf [16];
struct match_desc match;
data.raw = buf;
data.family = addr_parse_raw(data.raw, addr);
if (data.family < 0)
return NULL;
match_init(&match);
match.ns = ns;
if (match_if(&match, match_tunnel, &data))
return NULL;
return match_ambiguous(match) ? NULL : match_found(match);
}
struct if_entry *tunnel_find_addr(struct netns_entry *ns, struct addr *addr)
{
struct match_desc match;
match_init(&match);
match.ns = ns;
if (match_if(&match, match_tunnel, addr))
return NULL;
return match_ambiguous(match) ? NULL : match_found(match);
}