mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
netlib: Add support for adding/removing VLAN device
Add support for adding/removing VLAN device Signed-off-by: gaohedong <gaohedong@xiaomi.com>
This commit is contained in:
parent
b2f7ead2dd
commit
40c7982816
5 changed files with 159 additions and 0 deletions
|
|
@ -329,6 +329,11 @@ int netlib_getessid(FAR const char *ifname, FAR char *essid, size_t idlen);
|
|||
int netlib_setessid(FAR const char *ifname, FAR const char *essid);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_VLAN
|
||||
int netlib_add_vlan(FAR const char *ifname, int vlanid);
|
||||
int netlib_del_vlan(FAR const char *vlanif);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_ARP
|
||||
/* ARP Table Support */
|
||||
|
||||
|
|
|
|||
|
|
@ -118,6 +118,10 @@ if(CONFIG_NETUTILS_NETLIB)
|
|||
list(APPEND SRCS netlib_setmacaddr.c netlib_getmacaddr.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_NET_VLAN)
|
||||
list(APPEND SRCS netlib_addvlan.c netlib_delvlan.c)
|
||||
endif()
|
||||
|
||||
list(APPEND SRCS netlib_setmtu.c)
|
||||
|
||||
if(CONFIG_WIRELESS_IEEE802154)
|
||||
|
|
|
|||
|
|
@ -123,6 +123,10 @@ ifeq ($(CONFIG_NET_ETHERNET),y)
|
|||
CSRCS += netlib_setmacaddr.c netlib_getmacaddr.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NET_VLAN),y)
|
||||
CSRCS += netlib_addvlan.c netlib_delvlan.c
|
||||
endif
|
||||
|
||||
CSRCS += netlib_setmtu.c
|
||||
|
||||
ifeq ($(CONFIG_WIRELESS_IEEE802154),y)
|
||||
|
|
|
|||
74
netutils/netlib/netlib_addvlan.c
Normal file
74
netutils/netlib/netlib_addvlan.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/****************************************************************************
|
||||
* apps/netutils/netlib/netlib_addvlan.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#ifdef CONFIG_NET_VLAN
|
||||
|
||||
#include <nuttx/net/vlan.h>
|
||||
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netlib_add_vlan
|
||||
*
|
||||
* Description:
|
||||
* Add a VLAN interface to an existing network device.
|
||||
*
|
||||
* Parameters:
|
||||
* ifname - The name of the existing network device
|
||||
* vlanid - The VLAN identifier to be added
|
||||
*
|
||||
* Return:
|
||||
* 0 on success; -1 on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int netlib_add_vlan(FAR const char *ifname, int vlanid)
|
||||
{
|
||||
int ret = ERROR;
|
||||
|
||||
if (ifname && vlanid > 0)
|
||||
{
|
||||
int sockfd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL);
|
||||
if (sockfd >= 0)
|
||||
{
|
||||
struct vlan_ioctl_args ifv;
|
||||
|
||||
strlcpy(ifv.device1, ifname, sizeof(ifv.device1));
|
||||
ifv.u.VID = vlanid;
|
||||
ifv.cmd = ADD_VLAN_CMD;
|
||||
|
||||
ret = ioctl(sockfd, SIOCSIFVLAN, &ifv);
|
||||
close(sockfd);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_VLAN */
|
||||
72
netutils/netlib/netlib_delvlan.c
Normal file
72
netutils/netlib/netlib_delvlan.c
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/****************************************************************************
|
||||
* apps/netutils/netlib/netlib_delvlan.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#ifdef CONFIG_NET_VLAN
|
||||
|
||||
#include <nuttx/net/vlan.h>
|
||||
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netlib_del_vlan
|
||||
*
|
||||
* Description:
|
||||
* Remove a VLAN interface from an existing network device.
|
||||
*
|
||||
* Parameters:
|
||||
* vlanif - The name of the VLAN network device
|
||||
*
|
||||
* Return:
|
||||
* 0 on success; -1 on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int netlib_del_vlan(FAR const char *vlanif)
|
||||
{
|
||||
int ret = ERROR;
|
||||
|
||||
if (vlanif)
|
||||
{
|
||||
int sockfd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL);
|
||||
if (sockfd >= 0)
|
||||
{
|
||||
struct vlan_ioctl_args ifv;
|
||||
|
||||
strlcpy(ifv.device1, vlanif, sizeof(ifv.device1));
|
||||
ifv.cmd = DEL_VLAN_CMD;
|
||||
|
||||
ret = ioctl(sockfd, SIOCSIFVLAN, &ifv);
|
||||
close(sockfd);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_VLAN */
|
||||
Loading…
Add table
Add a link
Reference in a new issue