Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/net_utils.c
| Show All 34 Lines | |||||
| #include <errno.h> | #include <errno.h> | ||||
| #include <limits.h> | #include <limits.h> | ||||
| #include <md5.h> | #include <md5.h> | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include "bhyverun.h" | #include "bhyverun.h" | ||||
| #include "config.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(const 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); | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | 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 | ||||
| */ | */ | ||||
| MD5_CTX mdctx; | MD5_CTX mdctx; | ||||
| unsigned char digest[16]; | unsigned char digest[16]; | ||||
| char nstr[80]; | char nstr[80]; | ||||
| snprintf(nstr, sizeof(nstr), "%d-%d-%s", pi->pi_slot, | snprintf(nstr, sizeof(nstr), "%d-%d-%s", pi->pi_slot, | ||||
| pi->pi_func, vmname); | pi->pi_func, get_config_value("name")); | ||||
| MD5Init(&mdctx); | MD5Init(&mdctx); | ||||
| MD5Update(&mdctx, nstr, (unsigned int)strlen(nstr)); | MD5Update(&mdctx, nstr, (unsigned int)strlen(nstr)); | ||||
| MD5Final(digest, &mdctx); | MD5Final(digest, &mdctx); | ||||
| macaddr[0] = 0x00; | macaddr[0] = 0x00; | ||||
| macaddr[1] = 0xa0; | macaddr[1] = 0xa0; | ||||
| macaddr[2] = 0x98; | macaddr[2] = 0x98; | ||||
| macaddr[3] = digest[0]; | macaddr[3] = digest[0]; | ||||
| macaddr[4] = digest[1]; | macaddr[4] = digest[1]; | ||||
| macaddr[5] = digest[2]; | macaddr[5] = digest[2]; | ||||
| } | } | ||||