Date: Fri, 5 Aug 2016 14:13:39 GMT From: vincenzo@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r307238 - soc2016/vincenzo/head/usr.sbin/bhyve Message-ID: <201608051413.u75EDdqo017915@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: vincenzo Date: Fri Aug 5 14:13:39 2016 New Revision: 307238 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=307238 Log: bhyve: move net-utils functionalities in a separate module Added: soc2016/vincenzo/head/usr.sbin/bhyve/net_utils.c soc2016/vincenzo/head/usr.sbin/bhyve/net_utils.h Modified: soc2016/vincenzo/head/usr.sbin/bhyve/Makefile soc2016/vincenzo/head/usr.sbin/bhyve/net_backends.c soc2016/vincenzo/head/usr.sbin/bhyve/pci_ptnetmap_netif.c soc2016/vincenzo/head/usr.sbin/bhyve/pci_virtio_net.c Modified: soc2016/vincenzo/head/usr.sbin/bhyve/Makefile ============================================================================== --- soc2016/vincenzo/head/usr.sbin/bhyve/Makefile Fri Aug 5 14:11:23 2016 (r307237) +++ soc2016/vincenzo/head/usr.sbin/bhyve/Makefile Fri Aug 5 14:13:39 2016 (r307238) @@ -26,6 +26,7 @@ mevent.c \ mptbl.c \ net_backends.c \ + net_utils.c \ pci_ahci.c \ pci_emul.c \ pci_hostbridge.c \ Modified: soc2016/vincenzo/head/usr.sbin/bhyve/net_backends.c ============================================================================== --- soc2016/vincenzo/head/usr.sbin/bhyve/net_backends.c Fri Aug 5 14:11:23 2016 (r307237) +++ soc2016/vincenzo/head/usr.sbin/bhyve/net_backends.c Fri Aug 5 14:13:39 2016 (r307238) @@ -29,7 +29,6 @@ #include <sys/ioctl.h> #include <sys/mman.h> #include <sys/types.h> /* u_short etc */ -#include <net/ethernet.h> /* ETHER_ADDR_LEN */ #include <net/if.h> #include <errno.h> @@ -1060,59 +1059,3 @@ return ret; } - -/* - * Some utils functions, which should go in a separate module. - */ -#include <md5.h> -#include "pci_emul.h" -#include "bhyverun.h" - -int -net_parsemac(char *mac_str, uint8_t *mac_addr) -{ - struct ether_addr *ea; - char *tmpstr; - char zero_addr[ETHER_ADDR_LEN] = { 0, 0, 0, 0, 0, 0 }; - - tmpstr = strsep(&mac_str,"="); - - if ((mac_str != NULL) && (!strcmp(tmpstr,"mac"))) { - ea = ether_aton(mac_str); - - if (ea == NULL || ETHER_IS_MULTICAST(ea->octet) || - memcmp(ea->octet, zero_addr, ETHER_ADDR_LEN) == 0) { - fprintf(stderr, "Invalid MAC %s\n", mac_str); - return (EINVAL); - } else - memcpy(mac_addr, ea->octet, ETHER_ADDR_LEN); - } - - return (0); -} - -void -net_genmac(struct pci_devinst *pi, uint8_t *macaddr) -{ - /* - * The default MAC address is the standard NetApp OUI of 00-a0-98, - * followed by an MD5 of the PCI slot/func number and dev name - */ - MD5_CTX mdctx; - unsigned char digest[16]; - char nstr[80]; - - snprintf(nstr, sizeof(nstr), "%d-%d-%s", pi->pi_slot, - pi->pi_func, vmname); - - MD5Init(&mdctx); - MD5Update(&mdctx, nstr, strlen(nstr)); - MD5Final(digest, &mdctx); - - macaddr[0] = 0x00; - macaddr[1] = 0xa0; - macaddr[2] = 0x98; - macaddr[3] = digest[0]; - macaddr[4] = digest[1]; - macaddr[5] = digest[2]; -} Added: soc2016/vincenzo/head/usr.sbin/bhyve/net_utils.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2016/vincenzo/head/usr.sbin/bhyve/net_utils.c Fri Aug 5 14:13:39 2016 (r307238) @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 2011 NetApp, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "net_utils.h" +#include "bhyverun.h" +#include <md5.h> +#include <net/ethernet.h> +#include <string.h> +#include <stdio.h> +#include <errno.h> + +/* + * Some utils functions, used by net front-ends. + */ + +int +net_parsemac(char *mac_str, uint8_t *mac_addr) +{ + struct ether_addr *ea; + char *tmpstr; + char zero_addr[ETHER_ADDR_LEN] = { 0, 0, 0, 0, 0, 0 }; + + tmpstr = strsep(&mac_str,"="); + + if ((mac_str != NULL) && (!strcmp(tmpstr,"mac"))) { + ea = ether_aton(mac_str); + + if (ea == NULL || ETHER_IS_MULTICAST(ea->octet) || + memcmp(ea->octet, zero_addr, ETHER_ADDR_LEN) == 0) { + fprintf(stderr, "Invalid MAC %s\n", mac_str); + return (EINVAL); + } else + memcpy(mac_addr, ea->octet, ETHER_ADDR_LEN); + } + + return (0); +} + +void +net_genmac(struct pci_devinst *pi, uint8_t *macaddr) +{ + /* + * The default MAC address is the standard NetApp OUI of 00-a0-98, + * followed by an MD5 of the PCI slot/func number and dev name + */ + MD5_CTX mdctx; + unsigned char digest[16]; + char nstr[80]; + + snprintf(nstr, sizeof(nstr), "%d-%d-%s", pi->pi_slot, + pi->pi_func, vmname); + + MD5Init(&mdctx); + MD5Update(&mdctx, nstr, strlen(nstr)); + MD5Final(digest, &mdctx); + + macaddr[0] = 0x00; + macaddr[1] = 0xa0; + macaddr[2] = 0x98; + macaddr[3] = digest[0]; + macaddr[4] = digest[1]; + macaddr[5] = digest[2]; +} Added: soc2016/vincenzo/head/usr.sbin/bhyve/net_utils.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2016/vincenzo/head/usr.sbin/bhyve/net_utils.h Fri Aug 5 14:13:39 2016 (r307238) @@ -0,0 +1,33 @@ +/*- + * Copyright (c) 2011 NetApp, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdint.h> +#include "pci_emul.h" + +#ifndef _NET_UTILS_H_ +void net_genmac(struct pci_devinst *pi, uint8_t *macaddr); +int net_parsemac(char *mac_str, uint8_t *mac_addr); +#endif /* _NET_UTILS_H_ */ Modified: soc2016/vincenzo/head/usr.sbin/bhyve/pci_ptnetmap_netif.c ============================================================================== --- soc2016/vincenzo/head/usr.sbin/bhyve/pci_ptnetmap_netif.c Fri Aug 5 14:11:23 2016 (r307237) +++ soc2016/vincenzo/head/usr.sbin/bhyve/pci_ptnetmap_netif.c Fri Aug 5 14:13:39 2016 (r307238) @@ -46,6 +46,7 @@ #include "bhyverun.h" #include "pci_emul.h" +#include "net_utils.h" #include "net_backends.h" #ifndef PTNET_CSB_ALLOC @@ -132,12 +133,12 @@ ret = vm_io_reg_handler(vmctx, kick_addr /* ioaddr */, 0 /* in */, 0 /* mask_data */, 0 /* data */, VM_IO_REGH_KWEVENTS, - (void *)sc + i /* cookie */); + (void *)sc + 4*i /* cookie */); if (ret) { fprintf(stderr, "%s: vm_io_reg_handler %d\n", __func__, ret); } - cfg->entries[i].ioeventfd = (uint64_t) (sc + i); + cfg->entries[i].ioeventfd = (uint64_t) (sc + 4*i); } ret = ptnetmap_create(sc->ptbe, cfg); Modified: soc2016/vincenzo/head/usr.sbin/bhyve/pci_virtio_net.c ============================================================================== --- soc2016/vincenzo/head/usr.sbin/bhyve/pci_virtio_net.c Fri Aug 5 14:11:23 2016 (r307237) +++ soc2016/vincenzo/head/usr.sbin/bhyve/pci_virtio_net.c Fri Aug 5 14:13:39 2016 (r307238) @@ -57,6 +57,7 @@ #include "pci_emul.h" #include "mevent.h" #include "virtio.h" +#include "net_utils.h" #include "net_backends.h" #define VTNET_RINGSZ 1024
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201608051413.u75EDdqo017915>