Line data Source code
1 : /* 2 : * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #include <oper/interface.h> 7 : #include <oper/vm_interface.h> 8 : #include <oper/physical_interface.h> 9 : #include <oper/packet_interface.h> 10 : 11 0 : void Interface::ObtainOsSpecificParams(const std::string &name, Agent *agent) { 12 0 : os_params_.os_oper_state_ = false; 13 : 14 : struct ifreq ifr; 15 0 : memset(&ifr, 0, sizeof(ifr)); 16 0 : strncpy(ifr.ifr_name, name.c_str(), IF_NAMESIZE-1); 17 0 : int fd = socket(AF_LOCAL, SOCK_STREAM, 0); 18 0 : assert(fd >= 0); 19 0 : if (ioctl(fd, SIOCGIFHWADDR, (void *)&ifr) < 0) { 20 0 : LOG(ERROR, "Error <" << errno << ": " << strerror(errno) << 21 : "> querying mac-address for interface <" << name << "> " << 22 : "Agent-index <" << id_ << ">"); 23 0 : close(fd); 24 0 : return; 25 : } 26 : 27 0 : if (ioctl(fd, SIOCGIFFLAGS, (void *)&ifr) < 0) { 28 0 : LOG(ERROR, "Error <" << errno << ": " << strerror(errno) << 29 : "> querying flags for interface <" << name << "> " << 30 : "Agent-index <" << id_ << ">"); 31 0 : close(fd); 32 0 : return; 33 : } 34 : 35 0 : if ((ifr.ifr_flags & (IFF_UP | IFF_RUNNING)) == (IFF_UP | IFF_RUNNING)) { 36 0 : os_params_.os_oper_state_ = true; 37 : } 38 0 : close(fd); 39 : #if defined(__linux__) 40 0 : os_params_.mac_ = ifr.ifr_hwaddr; 41 : /* FIXME: Hack till priovisioing code changes for vhost0 */ 42 0 : if (agent->is_l3mh() && name.compare("vhost0") == 0) { 43 0 : os_params_.mac_ = MacAddress::FromString("00:00:5e:00:01:00"); 44 : } 45 : #endif 46 : 47 0 : int idx = if_nametoindex(name.c_str()); 48 0 : if (idx) 49 0 : os_params_.os_index_ = idx; 50 : } 51 : 52 0 : void VmInterface::ObtainOsSpecificParams(const std::string &name, Agent *agent) { 53 0 : Interface::ObtainOsSpecificParams(name, agent); 54 0 : } 55 : 56 0 : void PhysicalInterface::ObtainOsSpecificParams(const std::string &name, Agent *agent) { 57 0 : Interface::ObtainOsSpecificParams(name, agent); 58 0 : } 59 : 60 0 : void PacketInterface::ObtainOsSpecificParams(const std::string &name, Agent *agent) { 61 0 : Interface::ObtainOsSpecificParams(name, agent); 62 0 : }