net_utils.c (84659b24) | net_utils.c (154972af) |
---|---|
1/*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2011 NetApp, Inc. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 17 unchanged lines hidden (view full) --- 26 */ 27 28#include <sys/cdefs.h> 29__FBSDID("$FreeBSD$"); 30 31#include <sys/types.h> 32#include <net/ethernet.h> 33 | 1/*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2011 NetApp, Inc. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 17 unchanged lines hidden (view full) --- 26 */ 27 28#include <sys/cdefs.h> 29__FBSDID("$FreeBSD$"); 30 31#include <sys/types.h> 32#include <net/ethernet.h> 33 |
34#include <assert.h> |
|
34#include <errno.h> | 35#include <errno.h> |
36#include <limits.h> |
|
35#include <md5.h> 36#include <stdio.h> | 37#include <md5.h> 38#include <stdio.h> |
39#include <stdlib.h> |
|
37#include <string.h> 38 39#include "bhyverun.h" | 40#include <string.h> 41 42#include "bhyverun.h" |
43#include "debug.h" |
|
40#include "net_utils.h" 41 42int 43net_parsemac(char *mac_str, uint8_t *mac_addr) 44{ 45 struct ether_addr *ea; | 44#include "net_utils.h" 45 46int 47net_parsemac(char *mac_str, uint8_t *mac_addr) 48{ 49 struct ether_addr *ea; |
46 char *tmpstr; | |
47 char zero_addr[ETHER_ADDR_LEN] = { 0, 0, 0, 0, 0, 0 }; 48 | 50 char zero_addr[ETHER_ADDR_LEN] = { 0, 0, 0, 0, 0, 0 }; 51 |
49 tmpstr = strsep(&mac_str,"="); | 52 if (mac_str == NULL) 53 return (EINVAL); |
50 | 54 |
51 if ((mac_str != NULL) && (!strcmp(tmpstr,"mac"))) { 52 ea = ether_aton(mac_str); | 55 ea = ether_aton(mac_str); |
53 | 56 |
54 if (ea == NULL || ETHER_IS_MULTICAST(ea->octet) || 55 memcmp(ea->octet, zero_addr, ETHER_ADDR_LEN) == 0) { 56 fprintf(stderr, "Invalid MAC %s\n", mac_str); 57 return (EINVAL); 58 } else 59 memcpy(mac_addr, ea->octet, ETHER_ADDR_LEN); 60 } | 57 if (ea == NULL || ETHER_IS_MULTICAST(ea->octet) || 58 memcmp(ea->octet, zero_addr, ETHER_ADDR_LEN) == 0) { 59 EPRINTLN("Invalid MAC %s", mac_str); 60 return (EINVAL); 61 } else 62 memcpy(mac_addr, ea->octet, ETHER_ADDR_LEN); |
61 62 return (0); 63} 64 | 63 64 return (0); 65} 66 |
67int 68net_parsemtu(const char *mtu_str, unsigned long *mtu) 69{ 70 char *end; 71 unsigned long val; 72 73 assert(mtu_str != NULL); 74 75 if (*mtu_str == '-') 76 goto err; 77 78 val = strtoul(mtu_str, &end, 0); 79 80 if (*end != '\0') 81 goto err; 82 83 if (val == ULONG_MAX) 84 return (ERANGE); 85 86 if (val == 0 && errno == EINVAL) 87 return (EINVAL); 88 89 *mtu = val; 90 91 return (0); 92 93err: 94 errno = EINVAL; 95 return (EINVAL); 96} 97 |
|
65void 66net_genmac(struct pci_devinst *pi, uint8_t *macaddr) 67{ 68 /* 69 * The default MAC address is the standard NetApp OUI of 00-a0-98, 70 * followed by an MD5 of the PCI slot/func number and dev name 71 */ 72 MD5_CTX mdctx; --- 17 unchanged lines hidden --- | 98void 99net_genmac(struct pci_devinst *pi, uint8_t *macaddr) 100{ 101 /* 102 * The default MAC address is the standard NetApp OUI of 00-a0-98, 103 * followed by an MD5 of the PCI slot/func number and dev name 104 */ 105 MD5_CTX mdctx; --- 17 unchanged lines hidden --- |