Ignore:
Timestamp:
Nov 6, 2007, 11:01:53 AM (13 years ago)
Author:
Bruno Cornec
Message:
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod? silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian? keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René? Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mindi-busybox/networking/libiproute/iplink.c

    r821 r1770  
     1/* vi: set sw=4 ts=4: */
    12/*
    2  * iplink.c     "ip link".
     3 * iplink.c "ip link".
    34 *
    4  * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
     5 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
    56 *
    67 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
    78 */
    89
    9 #include "libbb.h"
    10 
    11 #include <sys/ioctl.h>
    12 #include <sys/socket.h>
    13 
    14 #include <errno.h>
    15 #include <string.h>
    16 #include <unistd.h>
    17 
     10//#include <sys/ioctl.h>
     11//#include <sys/socket.h>
    1812#include <net/if.h>
    1913#include <net/if_packet.h>
    2014#include <netpacket/packet.h>
    21 
    2215#include <net/ethernet.h>
    2316
     17#include "ip_common.h"  /* #include "libbb.h" is inside */
    2418#include "rt_names.h"
    2519#include "utils.h"
    26 #include "ip_common.h"
    27 
    28 /* take from linux/sockios.h */
     20
     21/* taken from linux/sockios.h */
    2922#define SIOCSIFNAME 0x8923      /* set interface name */
    3023
    31 static int do_link;
    32 
    33 static int on_off(char *msg)
    34 {
    35     bb_error_msg("Error: argument of \"%s\" must be \"on\" or \"off\"", msg);
    36     return -1;
    37 }
    38 
     24static void on_off(const char *msg) ATTRIBUTE_NORETURN;
     25static void on_off(const char *msg)
     26{
     27    bb_error_msg_and_die("error: argument of \"%s\" must be \"on\" or \"off\"", msg);
     28}
     29
     30/* Exits on error */
    3931static int get_ctl_fd(void)
    4032{
    41     int s_errno;
    4233    int fd;
    4334
     
    4536    if (fd >= 0)
    4637        return fd;
    47     s_errno = errno;
    4838    fd = socket(PF_PACKET, SOCK_DGRAM, 0);
    4939    if (fd >= 0)
    5040        return fd;
    51     fd = socket(PF_INET6, SOCK_DGRAM, 0);
    52     if (fd >= 0)
    53         return fd;
    54     errno = s_errno;
    55     perror("Cannot create control socket");
    56     return -1;
    57 }
    58 
    59 static int do_chflags(char *dev, __u32 flags, __u32 mask)
     41    return xsocket(PF_INET6, SOCK_DGRAM, 0);
     42}
     43
     44/* Exits on error */
     45static void do_chflags(char *dev, uint32_t flags, uint32_t mask)
    6046{
    6147    struct ifreq ifr;
    6248    int fd;
    63     int err;
    64 
    65     strcpy(ifr.ifr_name, dev);
     49
     50    strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
    6651    fd = get_ctl_fd();
    67     if (fd < 0)
    68         return -1;
    69     err = ioctl(fd, SIOCGIFFLAGS, &ifr);
    70     if (err) {
    71         perror("SIOCGIFFLAGS");
    72         close(fd);
    73         return -1;
    74     }
    75     if ((ifr.ifr_flags^flags)&mask) {
     52    xioctl(fd, SIOCGIFFLAGS, &ifr);
     53    if ((ifr.ifr_flags ^ flags) & mask) {
    7654        ifr.ifr_flags &= ~mask;
    77         ifr.ifr_flags |= mask&flags;
    78         err = ioctl(fd, SIOCSIFFLAGS, &ifr);
    79         if (err)
    80             perror("SIOCSIFFLAGS");
     55        ifr.ifr_flags |= mask & flags;
     56        xioctl(fd, SIOCSIFFLAGS, &ifr);
    8157    }
    8258    close(fd);
    83     return err;
    84 }
    85 
    86 static int do_changename(char *dev, char *newdev)
     59}
     60
     61/* Exits on error */
     62static void do_changename(char *dev, char *newdev)
    8763{
    8864    struct ifreq ifr;
    8965    int fd;
    90     int err;
    91 
    92     strcpy(ifr.ifr_name, dev);
    93     strcpy(ifr.ifr_newname, newdev);
     66
     67    strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
     68    strncpy(ifr.ifr_newname, newdev, sizeof(ifr.ifr_newname));
    9469    fd = get_ctl_fd();
    95     if (fd < 0)
    96         return -1;
    97     err = ioctl(fd, SIOCSIFNAME, &ifr);
    98     if (err) {
    99         perror("SIOCSIFNAME");
    100         close(fd);
    101         return -1;
    102     }
     70    xioctl(fd, SIOCSIFNAME, &ifr);
    10371    close(fd);
    104     return err;
    105 }
    106 
    107 static int set_qlen(char *dev, int qlen)
     72}
     73
     74/* Exits on error */
     75static void set_qlen(char *dev, int qlen)
    10876{
    10977    struct ifreq ifr;
     
    11179
    11280    s = get_ctl_fd();
    113     if (s < 0)
    114         return -1;
    115 
    11681    memset(&ifr, 0, sizeof(ifr));
    117     strcpy(ifr.ifr_name, dev);
     82    strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
    11883    ifr.ifr_qlen = qlen;
    119     if (ioctl(s, SIOCSIFTXQLEN, &ifr) < 0) {
    120         perror("SIOCSIFXQLEN");
    121         close(s);
    122         return -1;
    123     }
    124     close(s);
    125 
    126     return 0;
    127 }
    128 
    129 static int set_mtu(char *dev, int mtu)
     84    xioctl(s, SIOCSIFTXQLEN, &ifr);
     85    close(s);
     86}
     87
     88/* Exits on error */
     89static void set_mtu(char *dev, int mtu)
    13090{
    13191    struct ifreq ifr;
     
    13393
    13494    s = get_ctl_fd();
    135     if (s < 0)
    136         return -1;
    137 
    13895    memset(&ifr, 0, sizeof(ifr));
    139     strcpy(ifr.ifr_name, dev);
     96    strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
    14097    ifr.ifr_mtu = mtu;
    141     if (ioctl(s, SIOCSIFMTU, &ifr) < 0) {
    142         perror("SIOCSIFMTU");
    143         close(s);
    144         return -1;
    145     }
    146     close(s);
    147 
    148     return 0;
    149 }
    150 
     98    xioctl(s, SIOCSIFMTU, &ifr);
     99    close(s);
     100}
     101
     102/* Exits on error */
    151103static int get_address(char *dev, int *htype)
    152104{
     
    156108    int s;
    157109
    158     s = socket(PF_PACKET, SOCK_DGRAM, 0);
    159     if (s < 0) {
    160         perror("socket(PF_PACKET)");
    161         return -1;
    162     }
     110    s = xsocket(PF_PACKET, SOCK_DGRAM, 0);
    163111
    164112    memset(&ifr, 0, sizeof(ifr));
    165     strcpy(ifr.ifr_name, dev);
    166     if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
    167         perror("SIOCGIFINDEX");
    168         close(s);
    169         return -1;
    170     }
     113    strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
     114    xioctl(s, SIOCGIFINDEX, &ifr);
    171115
    172116    memset(&me, 0, sizeof(me));
     
    174118    me.sll_ifindex = ifr.ifr_ifindex;
    175119    me.sll_protocol = htons(ETH_P_LOOP);
    176     if (bind(s, (struct sockaddr*)&me, sizeof(me)) == -1) {
    177         perror("bind");
    178         close(s);
    179         return -1;
    180     }
     120    xbind(s, (struct sockaddr*)&me, sizeof(me));
    181121
    182122    alen = sizeof(me);
    183123    if (getsockname(s, (struct sockaddr*)&me, &alen) == -1) {
    184         perror("getsockname");
    185         close(s);
    186         return -1;
     124        bb_perror_msg_and_die("getsockname");
    187125    }
    188126    close(s);
     
    191129}
    192130
    193 static int parse_address(char *dev, int hatype, int halen, char *lla, struct ifreq *ifr)
     131/* Exits on error */
     132static void parse_address(char *dev, int hatype, int halen, char *lla, struct ifreq *ifr)
    194133{
    195134    int alen;
    196135
    197136    memset(ifr, 0, sizeof(*ifr));
    198     strcpy(ifr->ifr_name, dev);
     137    strncpy(ifr->ifr_name, dev, sizeof(ifr->ifr_name));
    199138    ifr->ifr_hwaddr.sa_family = hatype;
    200139    alen = ll_addr_a2n((unsigned char *)(ifr->ifr_hwaddr.sa_data), 14, lla);
    201140    if (alen < 0)
    202         return -1;
     141        exit(1);
    203142    if (alen != halen) {
    204         bb_error_msg("Wrong address (%s) length: expected %d bytes", lla, halen);
    205         return -1;
    206     }
    207     return 0;
    208 }
    209 
    210 static int set_address(struct ifreq *ifr, int brd)
     143        bb_error_msg_and_die("wrong address (%s) length: expected %d bytes", lla, halen);
     144    }
     145}
     146
     147/* Exits on error */
     148static void set_address(struct ifreq *ifr, int brd)
    211149{
    212150    int s;
    213151
    214152    s = get_ctl_fd();
    215     if (s < 0)
    216         return -1;
    217     if (ioctl(s, brd?SIOCSIFHWBROADCAST:SIOCSIFHWADDR, ifr) < 0) {
    218         perror(brd?"SIOCSIFHWBROADCAST":"SIOCSIFHWADDR");
    219         close(s);
    220         return -1;
    221     }
    222     close(s);
    223     return 0;
    224 }
    225 
    226 
     153    if (brd)
     154        xioctl(s, SIOCSIFHWBROADCAST, ifr);
     155    else
     156        xioctl(s, SIOCSIFHWADDR, ifr);
     157    close(s);
     158}
     159
     160
     161/* Return value becomes exitcode. It's okay to not return at all */
    227162static int do_set(int argc, char **argv)
    228163{
    229164    char *dev = NULL;
    230     __u32 mask = 0;
    231     __u32 flags = 0;
     165    uint32_t mask = 0;
     166    uint32_t flags = 0;
    232167    int qlen = -1;
    233168    int mtu = -1;
     
    237172    char *newname = NULL;
    238173    int htype, halen;
     174    static const char keywords[] ALIGN1 =
     175        "up\0""down\0""name\0""mtu\0""multicast\0""arp\0""addr\0""dev\0"
     176        "on\0""off\0";
     177    enum { ARG_up = 1, ARG_down, ARG_name, ARG_mtu, ARG_multicast, ARG_arp,
     178        ARG_addr, ARG_dev, PARM_on, PARM_off };
     179    smalluint key;
    239180
    240181    while (argc > 0) {
    241         if (strcmp(*argv, "up") == 0) {
     182        key = index_in_strings(keywords, *argv) + 1;
     183        if (key == ARG_up) {
    242184            mask |= IFF_UP;
    243185            flags |= IFF_UP;
    244         } else if (strcmp(*argv, "down") == 0) {
     186        } else if (key == ARG_down) {
    245187            mask |= IFF_UP;
    246188            flags &= ~IFF_UP;
    247         } else if (strcmp(*argv, "name") == 0) {
     189        } else if (key == ARG_name) {
    248190            NEXT_ARG();
    249191            newname = *argv;
    250         } else if (strcmp(*argv, "mtu") == 0) {
     192        } else if (key == ARG_mtu) {
    251193            NEXT_ARG();
    252194            if (mtu != -1)
     
    254196            if (get_integer(&mtu, *argv, 0))
    255197                invarg(*argv, "mtu");
    256         } else if (strcmp(*argv, "multicast") == 0) {
     198        } else if (key == ARG_multicast) {
    257199            NEXT_ARG();
    258200            mask |= IFF_MULTICAST;
    259             if (strcmp(*argv, "on") == 0) {
     201            key = index_in_strings(keywords, *argv) + 1;
     202            if (key == PARM_on) {
    260203                flags |= IFF_MULTICAST;
    261             } else if (strcmp(*argv, "off") == 0) {
     204            } else if (key == PARM_off) {
    262205                flags &= ~IFF_MULTICAST;
    263206            } else
    264                 return on_off("multicast");
    265         } else if (strcmp(*argv, "arp") == 0) {
     207                on_off("multicast");
     208        } else if (key == ARG_arp) {
    266209            NEXT_ARG();
    267210            mask |= IFF_NOARP;
    268             if (strcmp(*argv, "on") == 0) {
     211            key = index_in_strings(keywords, *argv) + 1;
     212            if (key == PARM_on) {
    269213                flags &= ~IFF_NOARP;
    270             } else if (strcmp(*argv, "off") == 0) {
     214            } else if (key == PARM_off) {
    271215                flags |= IFF_NOARP;
    272216            } else
    273                 return on_off("noarp");
    274         } else if (strcmp(*argv, "addr") == 0) {
     217                on_off("arp");
     218        } else if (key == ARG_addr) {
    275219            NEXT_ARG();
    276220            newaddr = *argv;
    277221        } else {
    278             if (strcmp(*argv, "dev") == 0) {
     222            if (key == ARG_dev) {
    279223                NEXT_ARG();
    280224            }
     
    287231
    288232    if (!dev) {
    289         bb_error_msg(bb_msg_requires_arg, "\"dev\"");
    290         exit(-1);
     233        bb_error_msg_and_die(bb_msg_requires_arg, "\"dev\"");
    291234    }
    292235
    293236    if (newaddr || newbrd) {
    294237        halen = get_address(dev, &htype);
    295         if (halen < 0)
    296             return -1;
    297238        if (newaddr) {
    298             if (parse_address(dev, htype, halen, newaddr, &ifr0) < 0)
    299                 return -1;
     239            parse_address(dev, htype, halen, newaddr, &ifr0);
    300240        }
    301241        if (newbrd) {
    302             if (parse_address(dev, htype, halen, newbrd, &ifr1) < 0)
    303                 return -1;
     242            parse_address(dev, htype, halen, newbrd, &ifr1);
    304243        }
    305244    }
    306245
    307246    if (newname && strcmp(dev, newname)) {
    308         if (do_changename(dev, newname) < 0)
    309             return -1;
     247        do_changename(dev, newname);
    310248        dev = newname;
    311249    }
    312250    if (qlen != -1) {
    313         if (set_qlen(dev, qlen) < 0)
    314             return -1;
     251        set_qlen(dev, qlen);
    315252    }
    316253    if (mtu != -1) {
    317         if (set_mtu(dev, mtu) < 0)
    318             return -1;
     254        set_mtu(dev, mtu);
    319255    }
    320256    if (newaddr || newbrd) {
    321257        if (newbrd) {
    322             if (set_address(&ifr1, 1) < 0)
    323                 return -1;
     258            set_address(&ifr1, 1);
    324259        }
    325260        if (newaddr) {
    326             if (set_address(&ifr0, 0) < 0)
    327                 return -1;
     261            set_address(&ifr0, 0);
    328262        }
    329263    }
    330264    if (mask)
    331         return do_chflags(dev, flags, mask);
     265        do_chflags(dev, flags, mask);
    332266    return 0;
    333267}
     
    336270{
    337271    preferred_family = AF_PACKET;
    338     do_link = 1;
    339272    return ipaddr_list_or_flush(argc, argv, 0);
    340273}
    341274
     275/* Return value becomes exitcode. It's okay to not return at all */
    342276int do_iplink(int argc, char **argv)
    343277{
    344     if (argc > 0) {
    345         if (matches(*argv, "set") == 0)
    346             return do_set(argc-1, argv+1);
    347         if (matches(*argv, "show") == 0 ||
    348             matches(*argv, "lst") == 0 ||
    349             matches(*argv, "list") == 0)
    350             return ipaddr_list_link(argc-1, argv+1);
    351     } else
     278    static const char keywords[] ALIGN1 =
     279        "set\0""show\0""lst\0""list\0";
     280    smalluint key;
     281    if (argc <= 0)
    352282        return ipaddr_list_link(0, NULL);
    353 
    354     bb_error_msg("Command \"%s\" is unknown.", *argv);
    355     exit(-1);
    356 }
     283    key = index_in_substrings(keywords, *argv) + 1;
     284    if (key == 0)
     285        bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
     286    argc--; argv++;
     287    if (key == 1) /* set */
     288        return do_set(argc, argv);
     289    else /* show, lst, list */
     290        return ipaddr_list_link(argc, argv);
     291}
Note: See TracChangeset for help on using the changeset viewer.