Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/net_utils.c
Show All 26 Lines | |||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <net/ethernet.h> | #include <net/ethernet.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <limits.h> | |||||
#include <md5.h> | #include <md5.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | |||||
#include <string.h> | #include <string.h> | ||||
#include "bhyverun.h" | #include "bhyverun.h" | ||||
#include "debug.h" | #include "debug.h" | ||||
#include "net_utils.h" | #include "net_utils.h" | ||||
int | int | ||||
net_parsemac(char *mac_str, uint8_t *mac_addr) | net_parsemac(char *mac_str, uint8_t *mac_addr) | ||||
{ | { | ||||
struct ether_addr *ea; | struct ether_addr *ea; | ||||
char zero_addr[ETHER_ADDR_LEN] = { 0, 0, 0, 0, 0, 0 }; | char zero_addr[ETHER_ADDR_LEN] = { 0, 0, 0, 0, 0, 0 }; | ||||
if (mac_str == NULL) | if (mac_str == NULL) | ||||
return (EINVAL); | return (EINVAL); | ||||
ea = ether_aton(mac_str); | ea = ether_aton(mac_str); | ||||
if (ea == NULL || ETHER_IS_MULTICAST(ea->octet) || | if (ea == NULL || ETHER_IS_MULTICAST(ea->octet) || | ||||
memcmp(ea->octet, zero_addr, ETHER_ADDR_LEN) == 0) { | memcmp(ea->octet, zero_addr, ETHER_ADDR_LEN) == 0) { | ||||
EPRINTLN("Invalid MAC %s", mac_str); | EPRINTLN("Invalid MAC %s", mac_str); | ||||
return (EINVAL); | return (EINVAL); | ||||
} else | } else | ||||
memcpy(mac_addr, ea->octet, ETHER_ADDR_LEN); | memcpy(mac_addr, ea->octet, ETHER_ADDR_LEN); | ||||
return (0); | |||||
} | |||||
int | |||||
net_parsemtu(const char *mtu_str, uint16_t *mtu) | |||||
{ | |||||
unsigned int val; | |||||
val = strtoul (mtu_str, NULL, 0); | |||||
if (val == ULONG_MAX) | |||||
return (ERANGE); | |||||
if (val < ETHERMIN || val > ETHERMTU_JUMBO) | |||||
rgrimes: Why restrict this to ETHER MTU's at all? And shouldnt that restriction actually be in the… | |||||
vmaffioneUnsubmitted Done Inline ActionsI think we need to follow the specification (sec 5.1.4.1) vmaffione: I think we need to follow the specification (sec 5.1.4.1)
According to the spec, the minimum… | |||||
return (EINVAL); | |||||
Done Inline ActionsI would s/10/0/. If someone wants to enter an MTU in hex that seems fine to permit. jhb: I would s/10/0/. If someone wants to enter an MTU in hex that seems fine to permit. | |||||
*mtu = (uint16_t)val; | |||||
return (0); | return (0); | ||||
} | } | ||||
void | void | ||||
net_genmac(struct pci_devinst *pi, uint8_t *macaddr) | net_genmac(struct pci_devinst *pi, uint8_t *macaddr) | ||||
{ | { | ||||
/* | /* | ||||
* The default MAC address is the standard NetApp OUI of 00-a0-98, | * 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 | * followed by an MD5 of the PCI slot/func number and dev name | ||||
Show All 19 Lines |
Why restrict this to ETHER MTU's at all? And shouldnt that restriction actually be in the kernel code that implements this and not rely on some userland bounds checking?