OpenSDN source code
interface_params.cc
Go to the documentation of this file.
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>
10 
11 void Interface::ObtainOsSpecificParams(const std::string &name, Agent *agent) {
12  os_params_.os_oper_state_ = false;
13 
14  struct ifreq ifr;
15  memset(&ifr, 0, sizeof(ifr));
16  strncpy(ifr.ifr_name, name.c_str(), IF_NAMESIZE-1);
17  int fd = socket(AF_LOCAL, SOCK_STREAM, 0);
18  assert(fd >= 0);
19  if (ioctl(fd, SIOCGIFHWADDR, (void *)&ifr) < 0) {
20  LOG(ERROR, "Error <" << errno << ": " << strerror(errno) <<
21  "> querying mac-address for interface <" << name << "> " <<
22  "Agent-index <" << id_ << ">");
23  close(fd);
24  return;
25  }
26 
27  if (ioctl(fd, SIOCGIFFLAGS, (void *)&ifr) < 0) {
28  LOG(ERROR, "Error <" << errno << ": " << strerror(errno) <<
29  "> querying flags for interface <" << name << "> " <<
30  "Agent-index <" << id_ << ">");
31  close(fd);
32  return;
33  }
34 
35  if ((ifr.ifr_flags & (IFF_UP | IFF_RUNNING)) == (IFF_UP | IFF_RUNNING)) {
37  }
38  close(fd);
39 #if defined(__linux__)
40  os_params_.mac_ = ifr.ifr_hwaddr;
41  /* FIXME: Hack till priovisioing code changes for vhost0 */
42  if (agent->is_l3mh() && name.compare("vhost0") == 0) {
43  os_params_.mac_ = MacAddress::FromString("00:00:5e:00:01:00");
44  }
45 #endif
46 
47  int idx = if_nametoindex(name.c_str());
48  if (idx)
49  os_params_.os_index_ = idx;
50 }
51 
52 void VmInterface::ObtainOsSpecificParams(const std::string &name, Agent *agent) {
54 }
55 
56 void PhysicalInterface::ObtainOsSpecificParams(const std::string &name, Agent *agent) {
58 }
59 
60 void PacketInterface::ObtainOsSpecificParams(const std::string &name, Agent *agent) {
62 }
Definition: agent.h:361
bool is_l3mh() const
Definition: agent.h:728
const std::string & name() const
Definition: interface.h:117
struct InterfaceOsParams os_params_
Definition: interface.h:191
size_t id_
Definition: interface.h:177
virtual void ObtainOsSpecificParams(const std::string &name, Agent *agent)
static MacAddress FromString(const std::string &str, boost::system::error_code *error=NULL)
Definition: mac_address.cc:72
virtual void ObtainOsSpecificParams(const std::string &name, Agent *agent)
virtual void ObtainOsSpecificParams(const std::string &name, Agent *agent)
Agent * agent() const
virtual void ObtainOsSpecificParams(const std::string &name, Agent *agent)
#define LOG(_Level, _Msg)
Definition: logging.h:35