Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 4205 Details for
Bug 7994
Patch to net-tools to allow mii-tool to activate/deactive interfaces based on media
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch to mii-tool (and man page) to add -a,--activate option
net-tools-1.60-mii-tool-activate.patch (text/plain), 10.76 KB, created by
Pat Double
on 2002-09-26 07:39:43 UTC
(
hide
)
Description:
Patch to mii-tool (and man page) to add -a,--activate option
Filename:
MIME Type:
Creator:
Pat Double
Created:
2002-09-26 07:39:43 UTC
Size:
10.76 KB
patch
obsolete
>diff -r -u net-tools-1.60/Makefile net-tools-1.60pbd/Makefile >--- net-tools-1.60/Makefile Sun Apr 15 09:34:31 2001 >+++ net-tools-1.60pbd/Makefile Fri Sep 20 10:27:56 2002 >@@ -218,7 +218,7 @@ > $(CC) $(LDFLAGS) -o ipmaddr ipmaddr.o $(NLIB) $(RESLIB) > > mii-tool: mii-tool.o >- $(CC) $(LDFLAGS) -o mii-tool mii-tool.o >+ $(CC) $(LDFLAGS) -o mii-tool mii-tool.o $(NLIB) > > installbin: > install -m 0755 -d ${BASEDIR}/sbin >Only in net-tools-1.60pbd: arp >Only in net-tools-1.60pbd: arp.o >Only in net-tools-1.60pbd: config.h >Only in net-tools-1.60pbd: config.make >Only in net-tools-1.60pbd: config.status >Only in net-tools-1.60pbd: hostname >Only in net-tools-1.60pbd: hostname.o >Only in net-tools-1.60pbd: ifconfig >Only in net-tools-1.60pbd: ifconfig.o >Only in net-tools-1.60pbd/lib: activate.o >Only in net-tools-1.60pbd/lib: af.o >Only in net-tools-1.60pbd/lib: arcnet.o >Only in net-tools-1.60pbd/lib: ash.o >Only in net-tools-1.60pbd/lib: ax25.o >Only in net-tools-1.60pbd/lib: ax25_gr.o >Only in net-tools-1.60pbd/lib: ddp.o >Only in net-tools-1.60pbd/lib: ddp_gr.o >Only in net-tools-1.60pbd/lib: ec_hw.o >Only in net-tools-1.60pbd/lib: econet.o >Only in net-tools-1.60pbd/lib: ether.o >Only in net-tools-1.60pbd/lib: fddi.o >Only in net-tools-1.60pbd/lib: frame.o >Only in net-tools-1.60pbd/lib: getargs.o >Only in net-tools-1.60pbd/lib: getroute.o >Only in net-tools-1.60pbd/lib: hdlclapb.o >Only in net-tools-1.60pbd/lib: hippi.o >Only in net-tools-1.60pbd/lib: hw.o >Only in net-tools-1.60pbd/lib: inet.o >Only in net-tools-1.60pbd/lib: inet6.o >Only in net-tools-1.60pbd/lib: inet6_gr.o >Only in net-tools-1.60pbd/lib: inet6_sr.o >Only in net-tools-1.60pbd/lib: inet_gr.o >Only in net-tools-1.60pbd/lib: inet_sr.o >Only in net-tools-1.60pbd/lib: interface.o >Only in net-tools-1.60pbd/lib: ipx.o >Only in net-tools-1.60pbd/lib: ipx_gr.o >Only in net-tools-1.60pbd/lib: ipx_sr.o >Only in net-tools-1.60pbd/lib: irda.o >Only in net-tools-1.60pbd/lib: libnet-tools.a >Only in net-tools-1.60pbd/lib: loopback.o >Only in net-tools-1.60pbd/lib: masq_info.o >Only in net-tools-1.60pbd/lib: netrom.o >Only in net-tools-1.60pbd/lib: netrom_gr.o >Only in net-tools-1.60pbd/lib: netrom_sr.o >Only in net-tools-1.60pbd/lib: nstrcmp.o >Only in net-tools-1.60pbd/lib: ppp.o >Only in net-tools-1.60pbd/lib: ppp_ac.o >Only in net-tools-1.60pbd/lib: proc.o >Only in net-tools-1.60pbd/lib: rose.o >Only in net-tools-1.60pbd/lib: rose_gr.o >Only in net-tools-1.60pbd/lib: setroute.o >Only in net-tools-1.60pbd/lib: sit.o >Only in net-tools-1.60pbd/lib: slip.o >Only in net-tools-1.60pbd/lib: slip_ac.o >Only in net-tools-1.60pbd/lib: sockets.o >Only in net-tools-1.60pbd/lib: strip.o >Only in net-tools-1.60pbd/lib: tr.o >Only in net-tools-1.60pbd/lib: tunnel.o >Only in net-tools-1.60pbd/lib: unix.o >Only in net-tools-1.60pbd/lib: util.o >Only in net-tools-1.60pbd/lib: x25.o >Only in net-tools-1.60pbd/lib: x25_gr.o >Only in net-tools-1.60pbd/lib: x25_sr.o >diff -r -u net-tools-1.60/man/en_US/mii-tool.8 net-tools-1.60pbd/man/en_US/mii-tool.8 >--- net-tools-1.60/man/en_US/mii-tool.8 Sun May 21 09:21:38 2000 >+++ net-tools-1.60pbd/man/en_US/mii-tool.8 Thu Sep 26 07:20:45 2002 >@@ -13,6 +13,7 @@ > [\fB\-R\fR, \fB\-\-reset\fR] > [\fB\-r\fR, \fB\-\-restart\fR] > [\fB\-w\fR, \fB\-\-watch\fR] >+[\fB\-a\fR, \fB\-\-activate=\fIinitscript\fR] > [\fB\-l\fR, \fB\-\-log\fR] > [\fB\-A\fR, \fB\-\-advertise=\fImedia,...\fR] > [\fB\-F\fR, \fB\-\-force=\fImedia\fR] >@@ -58,6 +59,14 @@ > Watch interface(s) and report changes in link status. The MII > interfaces are polled at one second intervals. > .TP >+\fB\-a\fR, \fB\-\-activate=\fIinitscript\fR >+Used with \fB-w\fR, activates and deactivates the selected >+interfaces when the media status changes. The >+\fBinitscript\fR is used to start and stop the interface and >+should take at least \fBstart\fR and \fBstop\fR as arguments. >+The name of the interface to start and stop is given by >+\fB\%s\fR. >+.TP > \fB\-l\fR, \fB\-\-log\fR > Used with \fB-w\fR, records link status changes in the system log > instead of printing on standard output. >@@ -76,3 +85,5 @@ > David Hinds \- dhinds@pcmcia.sourceforge.org > .br > Donald Becker \- becker@scyld.com >+.br >+Pat Double \- double@inebraska.com (Activate feature) >Only in net-tools-1.60pbd: mii-tool >diff -r -u net-tools-1.60/mii-tool.c net-tools-1.60pbd/mii-tool.c >--- net-tools-1.60/mii-tool.c Sun May 21 09:31:17 2000 >+++ net-tools-1.60pbd/mii-tool.c Thu Sep 26 07:28:37 2002 >@@ -15,6 +15,9 @@ > mii-diag is written/copyright 1997-2000 by Donald Becker > <becker@scyld.com> > >+ activate patch is written 2002 by Pat Double >+ <double@inebraska.com> >+ > This program is free software; you can redistribute it > and/or modify it under the terms of the GNU General Public > License as published by the Free Software Foundation. >@@ -51,6 +54,8 @@ > #include <linux/if_ether.h> > #endif > #include "mii.h" >+#include "interface.h" >+#include "sockets.h" > > #define MAX_ETH 8 /* Maximum # of interfaces */ > >@@ -81,6 +86,7 @@ > > struct option longopts[] = { > /* { name has_arg *flag val } */ >+ {"activate", 1, 0, 'a'}, /* Bring interface up/down when watching with -w. */ > {"advertise", 1, 0, 'A'}, /* Change capabilities advertised. */ > {"force", 1, 0, 'F'}, /* Change capabilities advertised. */ > {"phy", 1, 0, 'p'}, /* Set PHY (MII address) to report. */ >@@ -100,12 +106,14 @@ > opt_restart = 0, > opt_reset = 0, > opt_log = 0, >- opt_watch = 0; >+ opt_watch = 0, >+ opt_activate = 0; > static int nway_advertise = 0; > static int fixed_speed = 0; > static int override_phy = -1; >+static char* activate_script = 0; > >-static int skfd = -1; /* AF_INET socket for ioctl() calls. */ >+static int skfd_mii = -1; /* AF_INET socket for ioctl() calls. */ > static struct ifreq ifr; > > /*--------------------------------------------------------------------*/ >@@ -307,6 +315,51 @@ > > /*--------------------------------------------------------------------*/ > >+static void interface_cmd(char *ifname, char *start_or_stop) >+{ >+ char cmd[128]; >+ int pos; >+ >+ pos=snprintf(cmd, 128, activate_script, ifname); >+ >+ if (pos<127) >+ { >+ strcat(cmd, " "); >+ pos++; >+ } >+ >+ if ((pos+strlen(start_or_stop)) < 127 ) >+ strcat(cmd, start_or_stop); >+ >+ system(cmd); >+} >+ >+static void interface_up(char *ifname) >+{ >+ struct interface *ife; >+ >+ ife=lookup_interface(ifname); >+ if (!ife) return; >+ if (do_if_fetch(ife) < 0) return; >+ >+ if ((ife->flags & IFF_UP)==0) >+ interface_cmd(ifname, "start"); >+} >+ >+static void interface_down(char* ifname) >+{ >+ struct interface *ife; >+ >+ ife=lookup_interface(ifname); >+ if (!ife) return; >+ if (do_if_fetch(ife) < 0) return; >+ >+ if ((ife->flags & IFF_UP)!=0) >+ interface_cmd(ifname, "stop"); >+} >+ >+/*--------------------------------------------------------------------*/ >+ > static int do_one_xcvr(int skfd, char *ifname, int maybe) > { > struct mii_data *mii = (struct mii_data *)&ifr.ifr_data; >@@ -347,7 +400,16 @@ > mdio_write(skfd, MII_BMCR, bmcr); > } > >- if (!opt_restart && !opt_reset && !fixed_speed && !nway_advertise) >+ if (opt_activate) >+ { >+ int bmsr=mdio_read(skfd, MII_BMSR); >+ if (bmsr & MII_BMSR_LINK_VALID) >+ interface_up(ifname); >+ else >+ interface_down(ifname); >+ } >+ >+ if (!opt_activate && !opt_restart && !opt_reset && !fixed_speed && !nway_advertise) > show_basic_mii(skfd, mii->phy_id); > > return 0; >@@ -372,7 +434,21 @@ > now = (mdio_read(skfd, MII_BMCR) | > (mdio_read(skfd, MII_BMSR) << 16)); > if (status[index] && (status[index] != now)) >- show_basic_mii(skfd, mii->phy_id); >+ { >+ if (opt_activate) >+ { >+ int linkupnow=now & MII_BMSR_LINK_VALID<<16; >+ int linkupbefore=status[index] & MII_BMSR_LINK_VALID<<16; >+ if (linkupnow && !linkupbefore) >+ interface_up(ifname); >+ else if (!linkupnow && linkupbefore) >+ interface_down(ifname); >+ } >+ else >+ { >+ show_basic_mii(skfd, mii->phy_id); >+ } >+ } > status[index] = now; > } > >@@ -386,6 +462,8 @@ > -r, --restart restart autonegotiation > -w, --watch monitor for link status changes > -l, --log with -w, write events to syslog >+ -a, --activate=initscript with -w, activate (or deactivate) interface >+ using the given init script (interface in %s) > -A, --advertise=media,... advertise only specified media > -F, --force=media force specified media technology > media: 100baseT4, 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD, >@@ -396,8 +474,14 @@ > int i, c, ret, errflag = 0; > char s[6]; > >- while ((c = getopt_long(argc, argv, "A:F:p:lrRvVw?", longopts, 0)) != EOF) >+ while ((c = getopt_long(argc, argv, "A:F:p:a:lrRvVw?", longopts, 0)) != EOF) > switch (c) { >+ case 'a': >+ opt_activate++; >+ activate_script=malloc(strlen(optarg)+1); >+ if (activate_script) >+ strcpy(activate_script, optarg); >+ break; > case 'A': nway_advertise = parse_media(optarg); break; > case 'F': fixed_speed = parse_media(optarg); break; > case 'p': override_phy = atoi(optarg); break; >@@ -420,8 +504,14 @@ > if (opt_version) > printf(version); > >+ /* Open the socket for the library. */ >+ if ((skfd = sockets_open(0)) < 0) { >+ perror("socket"); >+ exit(1); >+ } >+ > /* Open a basic socket. */ >- if ((skfd = socket(AF_INET, SOCK_DGRAM,0)) < 0) { >+ if ((skfd_mii = socket(AF_INET, SOCK_DGRAM,0)) < 0) { > perror("socket"); > exit(-1); > } >@@ -431,14 +521,14 @@ > ret = 1; > for (i = 0; i < MAX_ETH; i++) { > sprintf(s, "eth%d", i); >- ret &= do_one_xcvr(skfd, s, 1); >+ ret &= do_one_xcvr(skfd_mii, s, 1); > } > if (ret) > fprintf(stderr, "no MII interfaces found\n"); > } else { > ret = 0; > for (i = optind; i < argc; i++) { >- ret |= do_one_xcvr(skfd, argv[i], 0); >+ ret |= do_one_xcvr(skfd_mii, argv[i], 0); > } > } > >@@ -448,15 +538,17 @@ > if (optind == argc) { > for (i = 0; i < MAX_ETH; i++) { > sprintf(s, "eth%d", i); >- watch_one_xcvr(skfd, s, i); >+ watch_one_xcvr(skfd_mii, s, i); > } > } else { > for (i = optind; i < argc; i++) >- watch_one_xcvr(skfd, argv[i], i-optind); >+ watch_one_xcvr(skfd_mii, argv[i], i-optind); > } > } > } > >+ close(skfd_mii); > close(skfd); >+ > return ret; > } >Only in net-tools-1.60pbd: mii-tool.o >Only in net-tools-1.60pbd: nameif >Only in net-tools-1.60pbd: nameif.o >Only in net-tools-1.60pbd: netstat >Only in net-tools-1.60pbd: netstat.o >Only in net-tools-1.60pbd: plipconfig >Only in net-tools-1.60pbd: plipconfig.o >Only in net-tools-1.60pbd: rarp >Only in net-tools-1.60pbd: rarp.o >Only in net-tools-1.60pbd: route >Only in net-tools-1.60pbd: route.o >Only in net-tools-1.60pbd: slattach >Only in net-tools-1.60pbd: slattach.o >Only in net-tools-1.60pbd: statistics.o >Only in net-tools-1.60pbd: version.h
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 7994
:
3957
| 4205 |
4206
|
4207
|
4208
|
4476
|
6581