OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
interface_params.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <oper/interface.h>
6 #include <oper/vm_interface.h>
9 
10 void Interface::ObtainOsSpecificParams(const std::string &name, Agent *agent) {
11  os_params_.os_oper_state_ = false;
12 
13  struct ifreq ifr;
14  memset(&ifr, 0, sizeof(ifr));
15  strncpy(ifr.ifr_name, name.c_str(), IF_NAMESIZE-1);
16  int fd = socket(AF_LOCAL, SOCK_STREAM, 0);
17  assert(fd >= 0);
18  if (ioctl(fd, SIOCGIFHWADDR, (void *)&ifr) < 0) {
19  LOG(ERROR, "Error <" << errno << ": " << strerror(errno) <<
20  "> querying mac-address for interface <" << name << "> " <<
21  "Agent-index <" << id_ << ">");
22  close(fd);
23  return;
24  }
25 
26  if (ioctl(fd, SIOCGIFFLAGS, (void *)&ifr) < 0) {
27  LOG(ERROR, "Error <" << errno << ": " << strerror(errno) <<
28  "> querying flags for interface <" << name << "> " <<
29  "Agent-index <" << id_ << ">");
30  close(fd);
31  return;
32  }
33 
34  if ((ifr.ifr_flags & (IFF_UP | IFF_RUNNING)) == (IFF_UP | IFF_RUNNING)) {
36  }
37  close(fd);
38 #if defined(__linux__)
39  os_params_.mac_ = ifr.ifr_hwaddr;
40  /* FIXME: Hack till priovisioing code changes for vhost0 */
41  if (agent->is_l3mh() && name.compare("vhost0") == 0) {
42  os_params_.mac_ = MacAddress::FromString("00:00:5e:00:01:00");
43  }
44 #endif
45 
46  int idx = if_nametoindex(name.c_str());
47  if (idx)
48  os_params_.os_index_ = idx;
49 }
50 
51 void VmInterface::ObtainOsSpecificParams(const std::string &name, Agent *agent) {
53 }
54 
55 void PhysicalInterface::ObtainOsSpecificParams(const std::string &name, Agent *agent) {
57 }
58 
59 void PacketInterface::ObtainOsSpecificParams(const std::string &name, Agent *agent) {
61 }
bool is_l3mh() const
Definition: agent.h:725
virtual void ObtainOsSpecificParams(const std::string &name, Agent *agent)
Definition: agent.h:358
virtual void ObtainOsSpecificParams(const std::string &name, Agent *agent)
virtual void ObtainOsSpecificParams(const std::string &name, Agent *agent)
virtual void ObtainOsSpecificParams(const std::string &name, Agent *agent)
#define LOG(_Level, _Msg)
Definition: logging.h:33
struct InterfaceOsParams os_params_
Definition: interface.h:188
static MacAddress FromString(const std::string &str, boost::system::error_code *error=NULL)
Definition: mac_address.cc:71
size_t id_
Definition: interface.h:174