lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 7 Jan 2010 22:18:55 +0100
From:	Michał Mirosław <mirqus@...il.com>
To:	Joe Perches <joe@...ches.com>
Cc:	H Hartley Sweeten <hartleys@...ionengravers.com>,
	David Miller <davem@...emloft.net>,
	"Maciej W. Rozycki" <macro@...ux-mips.org>,
	linux-kernel@...r.kernel.org, netdev <netdev@...r.kernel.org>
Subject: Re: [PATCH] lib/vsprintf.c: Add %pMF to format FDDI bit reversed MAC 
	addresses

2010/1/7 Joe Perches <joe@...ches.com>:
[...]
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index d4996cf..36959cc 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -25,6 +25,7 @@
>  #include <linux/kallsyms.h>
>  #include <linux/uaccess.h>
>  #include <linux/ioport.h>
> +#include <linux/bitrev.h>
>  #include <net/addrconf.h>
>
>  #include <asm/page.h>          /* for PAGE_SIZE */
> @@ -675,17 +676,37 @@ static char *resource_string(char *buf, char *end, struct resource *res,
>        return string(buf, end, sym, spec);
>  }
>
> +static u8 mac_byte(u8 val)
> +{
> +       return val;
> +}
> +
> +static u8 mac_byte_rev(u8 val)
> +{
> +       return bitrev8(val);
> +}
> +
>  static char *mac_address_string(char *buf, char *end, u8 *addr,
>                                struct printf_spec spec, const char *fmt)
>  {
>        char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
>        char *p = mac_addr;
>        int i;
> +       u8 (*mac_byte_fn)(u8 val);
> +       char separator;
> +
> +       if (fmt[1] == 'F') {            /* FDDI canonical format */
> +               mac_byte_fn = mac_byte_rev;
> +               separator = '-';
> +       } else {
> +               mac_byte_fn = mac_byte;
> +               separator  = ':';
> +       }
>
>        for (i = 0; i < 6; i++) {
> -               p = pack_hex_byte(p, addr[i]);
> +               p = pack_hex_byte(p, mac_byte_fn(addr[i]));
>                if (fmt[0] == 'M' && i != 5)
> -                       *p++ = ':';
> +                       *p++ = separator;
>        }
>        *p = '\0';
>
[...]

Something like the following might be smaller and faster - no
functions and their calls (just an idea);

int rev = (fmt[1] == 'F');
...
p = pack_hex_byte(p, rev ? bitrev8(addr[i]) : addr[i]);

Best Regards,
Michał Mirosław
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ