]>
git.proxmox.com Git - mirror_frr.git/blob - bfdd/linux.c
4 * Copyright (C) 2018 Network Device Education Foundation, Inc. ("NetDEF")
6 * FRR is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * FRR is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with FRR; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
32 int ptm_bfd_fetch_ifindex(const char *ifname
)
36 if (strlcpy(ifr
.ifr_name
, ifname
, sizeof(ifr
.ifr_name
))
37 > sizeof(ifr
.ifr_name
))
38 log_error("interface-to-index: name truncated ('%s' -> '%s')",
39 ifr
.ifr_name
, ifname
);
41 if (ioctl(bglobal
.bg_shop
, SIOCGIFINDEX
, &ifr
) == -1) {
42 log_error("interface-to-index: %s translation failed: %s",
43 ifname
, strerror(errno
));
47 return ifr
.ifr_ifindex
;
50 void ptm_bfd_fetch_local_mac(const char *ifname
, uint8_t *mac
)
54 if (strlcpy(ifr
.ifr_name
, ifname
, sizeof(ifr
.ifr_name
))
55 > sizeof(ifr
.ifr_name
))
56 log_error("interface-mac: name truncated ('%s' -> '%s')",
57 ifr
.ifr_name
, ifname
);
59 if (ioctl(bglobal
.bg_shop
, SIOCGIFHWADDR
, &ifr
) == -1) {
60 log_error("interface-mac: %s MAC retrieval failed: %s", ifname
,
65 memcpy(mac
, ifr
.ifr_hwaddr
.sa_data
, ETHERNET_ADDRESS_LENGTH
);
69 /* Was _fetch_portname_from_ifindex() */
70 void fetch_portname_from_ifindex(int ifindex
, char *ifname
, size_t ifnamelen
)
76 memset(&ifr
, 0, sizeof(ifr
));
77 ifr
.ifr_ifindex
= ifindex
;
79 if (ioctl(bglobal
.bg_shop
, SIOCGIFNAME
, &ifr
) == -1) {
80 log_error("index-to-interface: index %d failure: %s", ifindex
,
85 if (strlcpy(ifname
, ifr
.ifr_name
, ifnamelen
) >= ifnamelen
)
86 log_debug("index-to-interface: name truncated '%s' -> '%s'",
87 ifr
.ifr_name
, ifname
);
90 int bp_bind_dev(int sd
__attribute__((__unused__
)),
91 const char *dev
__attribute__((__unused__
)))
94 * TODO: implement this differently. It is not possible to
95 * SO_BINDTODEVICE after the daemon has dropped its privileges.
98 size_t devlen
= strlen(dev
) + 1;
100 if (setsockopt(sd
, SOL_SOCKET
, SO_BINDTODEVICE
, dev
, devlen
) == -1) {
101 log_warning("%s: setsockopt(SO_BINDTODEVICE, \"%s\"): %s",
102 __func__
, dev
, strerror(errno
));
110 #endif /* BFD_LINUX */