]>
git.proxmox.com Git - mirror_iproute2.git/blob - ip/tunnel.c
2 * Copyright (C)2006 USAGI/WIDE Project
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses>.
18 * split from ip_tunnel.c
22 * Masahide NAKAMURA @USAGI
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <sys/ioctl.h>
32 #include <netinet/in.h>
35 #include <linux/if_tunnel.h>
40 const char *tnl_strproto(__u8 proto
)
61 strcpy(buf
, "unknown");
68 int tnl_get_ioctl(const char *basedev
, void *p
)
74 strncpy(ifr
.ifr_name
, basedev
, IFNAMSIZ
);
75 ifr
.ifr_ifru
.ifru_data
= (void*)p
;
76 fd
= socket(preferred_family
, SOCK_DGRAM
, 0);
77 err
= ioctl(fd
, SIOCGETTUNNEL
, &ifr
);
79 fprintf(stderr
, "get tunnel \"%s\" failed: %s\n", basedev
,
86 int tnl_add_ioctl(int cmd
, const char *basedev
, const char *name
, void *p
)
92 if (cmd
== SIOCCHGTUNNEL
&& name
[0])
93 strncpy(ifr
.ifr_name
, name
, IFNAMSIZ
);
95 strncpy(ifr
.ifr_name
, basedev
, IFNAMSIZ
);
96 ifr
.ifr_ifru
.ifru_data
= p
;
97 fd
= socket(preferred_family
, SOCK_DGRAM
, 0);
98 err
= ioctl(fd
, cmd
, &ifr
);
100 fprintf(stderr
, "add tunnel \"%s\" failed: %s\n", ifr
.ifr_name
,
106 int tnl_del_ioctl(const char *basedev
, const char *name
, void *p
)
113 strncpy(ifr
.ifr_name
, name
, IFNAMSIZ
);
115 strncpy(ifr
.ifr_name
, basedev
, IFNAMSIZ
);
117 ifr
.ifr_ifru
.ifru_data
= p
;
118 fd
= socket(preferred_family
, SOCK_DGRAM
, 0);
119 err
= ioctl(fd
, SIOCDELTUNNEL
, &ifr
);
121 fprintf(stderr
, "delete tunnel \"%s\" failed: %s\n",
122 ifr
.ifr_name
, strerror(errno
));
127 static int tnl_gen_ioctl(int cmd
, const char *name
,
128 void *p
, int skiperr
)
134 strncpy(ifr
.ifr_name
, name
, IFNAMSIZ
);
135 ifr
.ifr_ifru
.ifru_data
= p
;
136 fd
= socket(preferred_family
, SOCK_DGRAM
, 0);
137 err
= ioctl(fd
, cmd
, &ifr
);
138 if (err
&& errno
!= skiperr
)
139 fprintf(stderr
, "%s: ioctl %x failed: %s\n", name
,
140 cmd
, strerror(errno
));
145 int tnl_prl_ioctl(int cmd
, const char *name
, void *p
)
147 return tnl_gen_ioctl(cmd
, name
, p
, -1);
150 int tnl_6rd_ioctl(int cmd
, const char *name
, void *p
)
152 return tnl_gen_ioctl(cmd
, name
, p
, -1);
155 int tnl_ioctl_get_6rd(const char *name
, void *p
)
157 return tnl_gen_ioctl(SIOCGET6RD
, name
, p
, EINVAL
);