Re: Memory leaks with GRE Tunnels

andrew may
2002-02-02T04:29:34Z

I don't think there is a kernel problem, there is an ioctl to delete
tunnels and it does work. if tun0 down does not delete the tunnel you
need to send down the ioctl as well. I don't know what user tools do
this for you, I have always done my own.

This is all the code ryou really need

{
struct ifreq ifr;
int fd;
int i=0;

if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
SYSLOG(LOG_DAEMON | LOG_ERR, "Cannot open socket to close tunnel(s)\n");
return;
}

sprintf(ifr.ifr_name,"tun%d", i);
if( (ioctl(fd, SIOCDELTUNNEL, &ifr) < 0) {
SYSLOG(LOG_DAEMON | LOG_ERR, "Can't DELTUNNEL %s (%m)\n", ifr.ifr_name);
}