Ejemplo n.º 1
0
void
ind_ovs_port_init(void)
{
    int nlerr;

    route_cache_sock = nl_socket_alloc();
    if (route_cache_sock == NULL) {
        LOG_ERROR("nl_socket_alloc failed");
        abort();
    }

    if ((nlerr = nl_cache_mngr_alloc(route_cache_sock, NETLINK_ROUTE,
                                     0, &route_cache_mngr)) < 0) {
        LOG_ERROR("nl_cache_mngr_alloc failed: %s", nl_geterror(nlerr));
        abort();
    }

    if ((nlerr = nl_cache_mngr_add(route_cache_mngr, "route/link", link_change_cb, NULL, &link_cache)) < 0) {
        LOG_ERROR("nl_cache_mngr_add failed: %s", nl_geterror(nlerr));
        abort();
    }

    if (ind_soc_socket_register(nl_cache_mngr_get_fd(route_cache_mngr),
                                (ind_soc_socket_ready_callback_f)route_cache_mngr_socket_cb,
                                NULL) < 0) {
        LOG_ERROR("failed to register socket");
        abort();
    }

    netlink_callbacks = nl_cb_alloc(NL_CB_DEFAULT);
    if (netlink_callbacks == NULL) {
        LOG_ERROR("failed to allocate netlink callbacks");
        abort();
    }
}
Ejemplo n.º 2
0
void
ind_ovs_port_finish(void)
{
        ind_soc_socket_unregister(nl_cache_mngr_get_fd(route_cache_mngr));
        nl_cache_mngr_free(route_cache_mngr);
        nl_socket_free(route_cache_sock);
}
Ejemplo n.º 3
0
NetlinkPoller::NetlinkPoller(
    folly::EventBase* eb,
    int fd,
    struct nl_cache_mngr* manager)
    : folly::EventHandler(eb, fd), manager_(manager) {
  DCHECK(eb) << "NULL pointer to EventBase";
  if (fd == -1) {
    int mngrFd = nl_cache_mngr_get_fd(manager);
    changeHandlerFD(mngrFd);
  }
  registerHandler(folly::EventHandler::READ | folly::EventHandler::PERSIST);
}
Ejemplo n.º 4
0
GWaterNlSource *
g_water_nl_source_new_for_cache_mngr(GMainContext *context, struct nl_cache_mngr *cache_mngr)
{
    g_return_val_if_fail(cache_mngr != NULL, NULL);

    GSource *source;
    GWaterNlSource *self;

    source = g_source_new(&_g_water_nl_source_funcs, sizeof(GWaterNlSource));
    self = (GWaterNlSource *)source;
    self->cache_mngr = cache_mngr;

    self->fd = g_source_add_unix_fd(source, nl_cache_mngr_get_fd(self->cache_mngr), G_IO_IN | G_IO_ERR | G_IO_HUP);

    g_source_attach(source, context);

    return self;
}
Ejemplo n.º 5
0
void NetlinkManager::startListening() {
  int fd = nl_cache_mngr_get_fd(nlResources_->manager);
  poller_ = std::make_unique<NetlinkPoller>(eb_, fd, nlResources_->manager);
}