From owner-freebsd-bugs@FreeBSD.ORG Wed Aug 29 20:20:02 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6CE701065675 for ; Wed, 29 Aug 2012 20:20:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 3E30A8FC18 for ; Wed, 29 Aug 2012 20:20:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q7TKK2R5025542 for ; Wed, 29 Aug 2012 20:20:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q7TKK2VF025541; Wed, 29 Aug 2012 20:20:02 GMT (envelope-from gnats) Resent-Date: Wed, 29 Aug 2012 20:20:02 GMT Resent-Message-Id: <201208292020.q7TKK2VF025541@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Harm Weites Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 19A4F1065673 for ; Wed, 29 Aug 2012 20:17:19 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 04A428FC15 for ; Wed, 29 Aug 2012 20:17:19 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q7TKHIrG013118 for ; Wed, 29 Aug 2012 20:17:18 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id q7TKHIBT013117; Wed, 29 Aug 2012 20:17:18 GMT (envelope-from nobody) Message-Id: <201208292017.q7TKHIBT013117@red.freebsd.org> Date: Wed, 29 Aug 2012 20:17:18 GMT From: Harm Weites To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/171173: etherswitchcfg vlangroup IOETHERSWITCHGETPORT error X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Aug 2012 20:20:02 -0000 >Number: 171173 >Category: bin >Synopsis: etherswitchcfg vlangroup IOETHERSWITCHGETPORT error >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Aug 29 20:20:01 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Harm Weites >Release: 10.0-CURRENT >Organization: >Environment: FreeBSD router1.weites.net 10.0-CURRENT FreeBSD 10.0-CURRENT #7 r239193M: Thu Jan 1 01:00:00 CET 1970 root@dummy:/home/harm/work/freebsd/head/obj/mipseb/mips.mips/usr/home/harm/work/freebsd/head/src/sys/TP-WN1043ND mips >Description: I'm observing the following issue when using etherswitchcfg on my TP-Link 1043ND embedded MIPS device. The default vlan configuration is done in the dev/etherswitchcfg init, creating vlan1 (wan port) and vlan2 (ports 1-4) with corresponding vlangroups. Those work as expected. When configuring the switch to have a vlan(group) per physical port, I receive the following error: etherswitchcfg: ioctl(IOETHERSWITCHGETPORT): Bad address >How-To-Repeat: # /sbin/etherswitchcfg port3 vlangroup 3 etherswitchcfg: ioctl(IOETHERSWITCHGETPORT): Bad address >Fix: While going through etherswitchcfg.c I noticed a subtle difference with set_port_vlangroup() and set_port_media(); the latter also uses ioctl(IOETHERSWITCHGETPORT) but does not fail and works just fine. It looks like there is a missing bzero() in set_port_vlangroup(), I've attached a patch to address that. While at it, I've also added a print to tell the user what'll happen, and a fix to prevent the function to segfault when a vlangroup is not supplied. Result of my fixed code: # ./etherswitchcfg port3 vlangroup 3 Set vlangroup of port 3 to 3 port3: vlangroup: 3 media: Ethernet autoselect (100baseTX ) status: active Patch attached with submission follows: Index: etherswitchcfg.c =================================================================== --- etherswitchcfg.c (revision 239193) +++ etherswitchcfg.c (working copy) @@ -136,13 +136,20 @@ int v; etherswitch_port_t p; + if (!argv[1]) + errx(EX_USAGE, "missing vlangroup #\n"); + v = strtol(argv[1], NULL, 0); if (v < 0 || v >= cfg->info.es_nvlangroups) errx(EX_USAGE, "vlangroup must be between 0 and %d", cfg->info.es_nvlangroups-1); + + bzero(&p, sizeof(p)); p.es_port = cfg->unit; if (ioctl(cfg->fd, IOETHERSWITCHGETPORT, &p) != 0) err(EX_OSERR, "ioctl(IOETHERSWITCHGETPORT)"); p.es_vlangroup = v; + + printf("Set vlangroup of port %d to %d\n", p.es_port, p.es_vlangroup); if (ioctl(cfg->fd, IOETHERSWITCHSETPORT, &p) != 0) err(EX_OSERR, "ioctl(IOETHERSWITCHSETPORT)"); } >Release-Note: >Audit-Trail: >Unformatted: