]> git.proxmox.com Git - mirror_frr.git/blame - bfdd/linux.c
sharpd: Allow sharpd to accept nexthop group as part of route install
[mirror_frr.git] / bfdd / linux.c
CommitLineData
e9e2c950
RZ
1/*
2 * Linux specific code
3 *
4 * Copyright (C) 2018 Network Device Education Foundation, Inc. ("NetDEF")
5 *
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
9 * later version.
10 *
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.
15 *
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
19 * 02111-1307, USA.
20 */
21
22#include <zebra.h>
23
24#ifdef BFD_LINUX
25
e9e2c950
RZ
26#include "bfd.h"
27
e9e2c950
RZ
28
29/*
30 * Definitions.
31 */
32int ptm_bfd_fetch_ifindex(const char *ifname)
33{
34 struct ifreq ifr;
35
36 if (strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name))
03e7f088
RZ
37 > sizeof(ifr.ifr_name))
38 log_error("interface-to-index: name truncated ('%s' -> '%s')",
39 ifr.ifr_name, ifname);
e9e2c950
RZ
40
41 if (ioctl(bglobal.bg_shop, SIOCGIFINDEX, &ifr) == -1) {
03e7f088
RZ
42 log_error("interface-to-index: %s translation failed: %s",
43 ifname, strerror(errno));
e9e2c950
RZ
44 return -1;
45 }
46
47 return ifr.ifr_ifindex;
48}
49
50void ptm_bfd_fetch_local_mac(const char *ifname, uint8_t *mac)
51{
52 struct ifreq ifr;
53
54 if (strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name))
03e7f088
RZ
55 > sizeof(ifr.ifr_name))
56 log_error("interface-mac: name truncated ('%s' -> '%s')",
57 ifr.ifr_name, ifname);
e9e2c950
RZ
58
59 if (ioctl(bglobal.bg_shop, SIOCGIFHWADDR, &ifr) == -1) {
03e7f088
RZ
60 log_error("interface-mac: %s MAC retrieval failed: %s", ifname,
61 strerror(errno));
e9e2c950
RZ
62 return;
63 }
64
65 memcpy(mac, ifr.ifr_hwaddr.sa_data, ETHERNET_ADDRESS_LENGTH);
66}
67
68
69/* Was _fetch_portname_from_ifindex() */
70void fetch_portname_from_ifindex(int ifindex, char *ifname, size_t ifnamelen)
71{
72 struct ifreq ifr;
73
74 ifname[0] = 0;
75
76 memset(&ifr, 0, sizeof(ifr));
77 ifr.ifr_ifindex = ifindex;
78
79 if (ioctl(bglobal.bg_shop, SIOCGIFNAME, &ifr) == -1) {
03e7f088
RZ
80 log_error("index-to-interface: index %d failure: %s", ifindex,
81 strerror(errno));
e9e2c950
RZ
82 return;
83 }
84
03e7f088
RZ
85 if (strlcpy(ifname, ifr.ifr_name, ifnamelen) >= ifnamelen)
86 log_debug("index-to-interface: name truncated '%s' -> '%s'",
87 ifr.ifr_name, ifname);
e9e2c950
RZ
88}
89
e9e2c950
RZ
90int bp_bind_dev(int sd __attribute__((__unused__)),
91 const char *dev __attribute__((__unused__)))
92{
93 /*
94 * TODO: implement this differently. It is not possible to
95 * SO_BINDTODEVICE after the daemon has dropped its privileges.
96 */
97#if 0
98 size_t devlen = strlen(dev) + 1;
99
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));
103 return -1;
104 }
105#endif
106
107 return 0;
108}
109
e9e2c950 110#endif /* BFD_LINUX */