Example #1
0
bool BcmRoute::deleteLpmRoute(int unitNumber,
                              opennsl_vrf_t vrf,
                              const folly::IPAddress& prefix,
                              uint8_t prefixLength) {
  opennsl_l3_route_t rt;
  initL3RouteFromArgs(&rt, vrf, prefix, prefixLength);
  auto rc = opennsl_l3_route_delete(unitNumber, &rt);
  if (OPENNSL_FAILURE(rc)) {
    LOG(ERROR) << "Failed to delete a route entry for " << prefix << "/"
               << static_cast<int>(prefixLength)
               << " Error: " << opennsl_errmsg(rc);
    return false;
  } else {
    VLOG(3) << "deleted a route entry for " << prefix.str() << "/"
            << static_cast<int>(prefixLength);
  }
  return true;
}
Example #2
0
void TunManager::addRemoveTunAddress(
    const std::string& name, uint32_t ifIndex,
    folly::IPAddress addr, uint8_t mask, bool add) {
  struct {
    struct nlmsghdr n;
    struct ifaddrmsg ifa;
    char buf[256];
  } req;
  memset(&req, 0, sizeof(req));
  req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
  if (add) {
    req.n.nlmsg_flags = NLM_F_REQUEST|NLM_F_CREATE|NLM_F_EXCL;
    req.n.nlmsg_type = RTM_NEWADDR;
  } else {
    req.n.nlmsg_flags = NLM_F_REQUEST;
    req.n.nlmsg_type = RTM_DELADDR;
  }
  if (addr.isV4()) {
    req.ifa.ifa_family = AF_INET;
    addattr_l(&req.n, sizeof(req), IFA_LOCAL, addr.asV4().bytes(),
              folly::IPAddressV4::byteCount());
  } else {
    req.ifa.ifa_family = AF_INET6;
    addattr_l(&req.n, sizeof(req), IFA_LOCAL, addr.asV6().bytes(),
              folly::IPAddressV6::byteCount());
  }
  req.ifa.ifa_prefixlen = mask;
  req.ifa.ifa_index = ifIndex;
  auto ret = rtnl_talk(&rth_, &req.n, 0, 0, nullptr);
  sysCheckError(ret, "Failed to ", add ? "add" : "remove",
                " address ", addr, "/", static_cast<int>(mask),
                " to interface ", name, " @ index ", ifIndex);
  LOG(INFO) << (add ? "Added" : "Removed") << " address " << addr.str() << "/"
            << static_cast<int>(mask) << " on interface " << name
            << " @ index " << ifIndex;
}