lldpd
struct lldpd *lldpd = ctl->ctl_lldpd;
ctl->ctl_handler(lldpd, ctl, fd);
static void ctl_msap(struct lldpd *, struct lldpd_ctl *, int);
static ssize_t ctl_msap_req_next(struct lldpd *, struct lldpd_ctl *,
static void ctl_msap_req_end(struct lldpd *, struct lldpd_ctl *,
ctl_msap_req(struct lldpd *lldpd, struct lldpd_ctl *ctl,
return (ctl_msap_req_next(lldpd, ctl, TAILQ_FIRST(&lldpd->msaps)));
ctl_msap(struct lldpd *lldpd, struct lldpd_ctl *ctl, int fd)
lldp_msap_rele(lldpd, msap);
ctl_close(lldpd, ctl);
rv = ctl_msap_req_next(lldpd, ctl, TAILQ_NEXT(msap, msap_aentry));
lldp_msap_rele(lldpd, msap);
ctl_close(lldpd, ctl);
ctl_msap_req_next(struct lldpd *lldpd, struct lldpd_ctl *ctl,
ctx->msap = lldp_msap_take(lldpd, msap);
ctl_msap_req_end(struct lldpd *lldpd, struct lldpd_ctl *ctl, int fd)
ctl_close(lldpd, ctl);
ctl_done(lldpd, ctl);
struct lldpd *lldpd = arg;
lwarn("control socket %s accept", lldpd->ctl_path);
ctl->ctl_lldpd = lldpd;
getall(struct lldpd *lldpd)
ifp->if_lldpd = lldpd;
struct lldpd *if_lldpd;
if (RBT_INSERT(ifaces, &lldpd->ifaces, ifp) != NULL) {
if (setsockopt(EVENT_FD(&lldpd->en_ev),
struct lldpd *ctl_lldpd;
void (*ctl_handler)(struct lldpd *, struct lldpd_ctl *, int fd);
static void rtsock_open(struct lldpd *);
static void ensock_open(struct lldpd *);
static void ctlsock_open(struct lldpd *);
static int getall(struct lldpd *);
struct lldpd _lldpd = {
struct lldpd *lldpd = &_lldpd; /* let me use -> consistently */
lldpd->ctl_path = optarg;
rtsock_open(lldpd);
ensock_open(lldpd);
ctlsock_open(lldpd);
lldpd->s = socket(AF_INET, SOCK_DGRAM, 0);
if (lldpd->s == -1)
if (getall(lldpd) == -1)
event_set(&lldpd->rt_ev, EVENT_FD(&lldpd->rt_ev),
EV_READ|EV_PERSIST, rtsock_recv, lldpd);
event_set(&lldpd->en_ev, EVENT_FD(&lldpd->en_ev),
EV_READ|EV_PERSIST, ensock_recv, lldpd);
event_set(&lldpd->ctl_ev, EVENT_FD(&lldpd->ctl_ev),
EV_READ|EV_PERSIST, ctlsock_accept, lldpd);
event_add(&lldpd->rt_ev, NULL);
event_add(&lldpd->en_ev, NULL);
event_add(&lldpd->ctl_ev, NULL);
agent_counter_inc(struct lldpd *lldpd, struct iface *ifp,
lldpd->agent_counters[c]++;
lldp_msap_take(struct lldpd *lldpd, struct lldp_msap *msap)
lldp_msap_rele(struct lldpd *lldpd, struct lldp_msap *msap)
TAILQ_REMOVE(&lldpd->msaps, msap, msap_aentry);
struct lldpd *lldpd = ifp->if_lldpd;
agent_counter_inc(lldpd, ifp, statsAgeoutsTotal);
rtsock_open(struct lldpd *lldpd)
event_set(&lldpd->rt_ev, s, 0, NULL, NULL);
iface_insert(struct lldpd *lldpd, struct iface *ifp)
return (RBT_INSERT(ifaces, &lldpd->ifaces, ifp));
iface_find(struct lldpd *lldpd, const char *ifname, int ifindex)
return (RBT_FIND(ifaces, &lldpd->ifaces, (struct iface *)&key));
iface_remove(struct lldpd *lldpd, struct iface *ifp)
RBT_REMOVE(ifaces, &lldpd->ifaces, ifp);
rtsock_if_attach(struct lldpd *lldpd, const struct if_announcemsghdr *ifan)
if (ioctl(lldpd->s, SIOCGIFDATA, &ifr) == -1) {
ifp->if_lldpd = lldpd;
if (iface_insert(lldpd, ifp) != NULL) {
if (setsockopt(EVENT_FD(&lldpd->en_ev),
rtsock_if_detach(struct lldpd *lldpd, const struct if_announcemsghdr *ifan)
ifp = iface_find(lldpd, ifan->ifan_name, ifan->ifan_index);
if (setsockopt(EVENT_FD(&lldpd->en_ev),
iface_remove(lldpd, ifp);
rtsock_ifannounce(struct lldpd *lldpd, const struct rt_msghdr *rtm, size_t len)
rtsock_if_attach(lldpd, ifan);
rtsock_if_detach(lldpd, ifan);
struct lldpd *lldpd = arg;
rtsock_ifannounce(lldpd, rtm, rv);
ensock_open(struct lldpd *lldpd)
event_set(&lldpd->en_ev, s, 0, NULL, NULL);
struct lldpd *lldpd = arg;
ifp = RBT_FIND(ifaces, &lldpd->ifaces, (struct iface *)&key);
agent_counter_inc(lldpd, ifp, statsFramesInTotal);
agent_counter_inc(lldpd, ifp,
TAILQ_INSERT_TAIL(&lldpd->msaps, msap, msap_aentry);
lldp_msap_rele(lldpd, msap);
TAILQ_REMOVE(&lldpd->msaps, msap,
agent_counter_inc(lldpd, ifp,
agent_counter_inc(lldpd, ifp, statsFramesDiscardedTotal);
agent_counter_inc(lldpd, ifp, statsFramesInErrorsTotal);
ctlsock_open(struct lldpd *lldpd)
const char *path = lldpd->ctl_path;
event_set(&lldpd->ctl_ev, s, 0, NULL, NULL);
ctl_close(struct lldpd *lldpd, struct lldpd_ctl *ctl)
static ssize_t ctl_ping(struct lldpd *, struct lldpd_ctl *,
static ssize_t ctl_msap_req(struct lldpd *, struct lldpd_ctl *,
struct lldpd *lldpd = ctl->ctl_lldpd;
ctl_close(lldpd, ctl);
ctl_close(lldpd, ctl);
ctl_close(lldpd, ctl);
rv = ctl_ping(lldpd, ctl, buf, len);
rv = ctl_msap_req(lldpd, ctl, buf, len);
ctl_close(lldpd, ctl);
(*ctl->ctl_handler)(lldpd, ctl, fd);
ctl_done(struct lldpd *lldpd, struct lldpd_ctl *ctl)
ctl_pong(struct lldpd *lldpd, struct lldpd_ctl *ctl, int fd)
ctl_close(lldpd, ctl);
ctl_done(lldpd, ctl);
ctl_ping(struct lldpd *lldpd, struct lldpd_ctl *ctl,