This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 779bd1713 system/brctl: Add Ethernet bridge configuration command.
779bd1713 is described below

commit 779bd171387b89f38c60c916b4605e5cea62f4e5
Author: Daniel P. Carvalho <[email protected]>
AuthorDate: Thu Oct 8 11:58:04 2026 -0300

    system/brctl: Add Ethernet bridge configuration command.
    
    Add the brctl command to create and delete Ethernet bridges and to add or
    remove their ports, using the SIOCBRADDBR, SIOCBRDELBR, SIOCBRADDIF and
    SIOCBRDELIF ioctl commands.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Daniel P. Carvalho <[email protected]>
---
 system/brctl/CMakeLists.txt |  33 ++++++++++++
 system/brctl/Kconfig        |  31 +++++++++++
 system/brctl/Make.defs      |  25 +++++++++
 system/brctl/Makefile       |  36 +++++++++++++
 system/brctl/brctl.c        | 127 ++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 252 insertions(+)

diff --git a/system/brctl/CMakeLists.txt b/system/brctl/CMakeLists.txt
new file mode 100644
index 000000000..6e819bb75
--- /dev/null
+++ b/system/brctl/CMakeLists.txt
@@ -0,0 +1,33 @@
+# 
##############################################################################
+# apps/system/brctl/CMakeLists.txt
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+# 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.
+#
+# 
##############################################################################
+
+if(CONFIG_SYSTEM_BRCTL)
+  nuttx_add_application(
+    NAME
+    brctl
+    SRCS
+    brctl.c
+    STACKSIZE
+    ${CONFIG_SYSTEM_BRCTL_STACKSIZE}
+    PRIORITY
+    ${CONFIG_SYSTEM_BRCTL_PRIORITY})
+endif()
diff --git a/system/brctl/Kconfig b/system/brctl/Kconfig
new file mode 100644
index 000000000..f4323c0d9
--- /dev/null
+++ b/system/brctl/Kconfig
@@ -0,0 +1,31 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config SYSTEM_BRCTL
+       tristate "Ethernet bridge 'brctl' command"
+       default n
+       depends on NET_BRIDGE
+       ---help---
+               Enable the 'brctl' command to create Ethernet bridges and to 
add or
+               remove their ports.
+
+if SYSTEM_BRCTL
+
+config SYSTEM_BRCTL_PROGNAME
+       string "brctl program name"
+       default "brctl"
+       ---help---
+               This is the name of the program that will be used when the NSH 
ELF
+               program is installed.
+
+config SYSTEM_BRCTL_PRIORITY
+       int "brctl task priority"
+       default 100
+
+config SYSTEM_BRCTL_STACKSIZE
+       int "brctl stack size"
+       default DEFAULT_TASK_STACKSIZE
+
+endif
diff --git a/system/brctl/Make.defs b/system/brctl/Make.defs
new file mode 100644
index 000000000..9a6b2276f
--- /dev/null
+++ b/system/brctl/Make.defs
@@ -0,0 +1,25 @@
+############################################################################
+# apps/system/brctl/Make.defs
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+# 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.
+#
+############################################################################
+
+ifneq ($(CONFIG_SYSTEM_BRCTL),)
+CONFIGURED_APPS += $(APPDIR)/system/brctl
+endif
diff --git a/system/brctl/Makefile b/system/brctl/Makefile
new file mode 100644
index 000000000..f1c40b79f
--- /dev/null
+++ b/system/brctl/Makefile
@@ -0,0 +1,36 @@
+############################################################################
+# apps/system/brctl/Makefile
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+# 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.
+#
+############################################################################
+
+include $(APPDIR)/Make.defs
+
+# Ethernet bridge configuration command
+
+PROGNAME = $(CONFIG_SYSTEM_BRCTL_PROGNAME)
+PRIORITY = $(CONFIG_SYSTEM_BRCTL_PRIORITY)
+STACKSIZE = $(CONFIG_SYSTEM_BRCTL_STACKSIZE)
+MODULE = $(CONFIG_SYSTEM_BRCTL)
+
+# Files
+
+MAINSRC = brctl.c
+
+include $(APPDIR)/Application.mk
diff --git a/system/brctl/brctl.c b/system/brctl/brctl.c
new file mode 100644
index 000000000..1fec14213
--- /dev/null
+++ b/system/brctl/brctl.c
@@ -0,0 +1,127 @@
+/****************************************************************************
+ * apps/system/brctl/brctl.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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>
+
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <net/if.h>
+#include <nuttx/net/ioctl.h>
+#include <nuttx/net/netconfig.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void brctl_usage(FAR const char *progname)
+{
+  fprintf(stderr, "Usage:\n");
+  fprintf(stderr, "  %s addbr <bridge>\n", progname);
+  fprintf(stderr, "  %s delbr <bridge>\n", progname);
+  fprintf(stderr, "  %s addif <bridge> <device>\n", progname);
+  fprintf(stderr, "  %s delif <bridge> <device>\n", progname);
+}
+
+static int brctl_ifcmd(int sockfd, int cmd, FAR const char *bridge,
+                       FAR const char *ifname)
+{
+  struct ifreq req;
+
+  memset(&req, 0, sizeof(req));
+  strlcpy(req.ifr_name, bridge, IFNAMSIZ);
+  req.ifr_ifindex = if_nametoindex(ifname);
+  if (req.ifr_ifindex == 0)
+    {
+      return -1;
+    }
+
+  return ioctl(sockfd, cmd, (unsigned long)(uintptr_t)&req);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, FAR char *argv[])
+{
+  FAR const char *cmd;
+  int sockfd;
+  int ret;
+
+  if (argc < 3)
+    {
+      brctl_usage(argv[0]);
+      return EXIT_FAILURE;
+    }
+
+  cmd = argv[1];
+
+  sockfd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL);
+  if (sockfd < 0)
+    {
+      fprintf(stderr, "ERROR: socket failed: %d\n", errno);
+      return EXIT_FAILURE;
+    }
+
+  if (strcmp(cmd, "addbr") == 0 && argc == 3)
+    {
+      ret = ioctl(sockfd, SIOCBRADDBR, (unsigned long)(uintptr_t)argv[2]);
+    }
+  else if (strcmp(cmd, "delbr") == 0 && argc == 3)
+    {
+      ret = ioctl(sockfd, SIOCBRDELBR, (unsigned long)(uintptr_t)argv[2]);
+    }
+  else if (strcmp(cmd, "addif") == 0 && argc == 4)
+    {
+      ret = brctl_ifcmd(sockfd, SIOCBRADDIF, argv[2], argv[3]);
+    }
+  else if (strcmp(cmd, "delif") == 0 && argc == 4)
+    {
+      ret = brctl_ifcmd(sockfd, SIOCBRDELIF, argv[2], argv[3]);
+    }
+  else
+    {
+      close(sockfd);
+      brctl_usage(argv[0]);
+      return EXIT_FAILURE;
+    }
+
+  if (ret < 0)
+    {
+      fprintf(stderr, "ERROR: brctl %s failed: %s\n", cmd,
+              strerror(errno));
+    }
+
+  close(sockfd);
+  return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+}

Reply via email to