2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
14 * Copyright (C) 2008 John Crispin <blogic@openwrt.org>
15 * Copyright (C) 2008 Steven Barth <steven@midlink.org>
19 #include <net/if_arp.h>
20 #include <net/route.h>
24 #include <linux/sockios.h>
25 #include <linux/if_vlan.h>
28 #include <sys/types.h>
36 extern int sock_ifconfig
;
39 static inline int _vlan_add(lua_State
*L
, int i
)
41 struct vlan_ioctl_args ifr
;
42 int a
= (i
== ADD_VLAN_CMD
)?(2):(1);
44 if(lua_gettop(L
) != a
)
46 lua_pushstring(L
, "invalid arg list");
50 ifname
= (char *)lua_tostring (L
, 1);
53 ifr
.u
.VID
= (int)lua_tointeger (L
, 2);
54 strncpy(ifr
.device1
, ifname
, IFNAMSIZ
);
55 if(!ioctl(sock_ifconfig
, SIOCSIFVLAN
, &ifr
))
56 lua_pushboolean(L
, 1);
58 lua_pushboolean(L
, 0);
62 int vlan_add(lua_State
*L
)
64 return _vlan_add(L
, ADD_VLAN_CMD
);
67 int vlan_del(lua_State
*L
)
69 return _vlan_add(L
, DEL_VLAN_CMD
);
72 int vlan_getall(lua_State
*L
)
74 struct dirent
**namelist
;
75 int n
= 0, i
, count
= 0;
76 count
= scandir("/proc/net/vlan/", &namelist
, NULL
, alphasort
);
80 for (i
= 0; i
< count
; i
++)
82 if(strcmp(namelist
[i
]->d_name
, "config") && (*namelist
[i
]->d_name
!= '.'))
85 lua_pushinteger(L
, n
);
86 lua_pushstring(L
, namelist
[i
]->d_name
);