]> git.ipfire.org Git - thirdparty/lldpd.git/blame - src/daemon/forward-linux.c
build: run cross-platforms test on ubuntu-latest
[thirdparty/lldpd.git] / src / daemon / forward-linux.c
CommitLineData
c3e340b6
VB
1/* -*- mode: c; c-file-style: "openbsd" -*- */
2/*
3 * Copyright (c) 2013 Vincent Bernat <bernat@luffy.cx>
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "lldpd.h"
19
20#include <unistd.h>
21
f540397c 22static int
1cf1a23f
AQ
23ip_forwarding_enabled(int af)
24{
25 int fd, rc = -1;
f540397c 26 const char *fname;
1cf1a23f
AQ
27 char status;
28
29 if (af == LLDPD_AF_IPV4)
30 fname = PROCFS_SYS_NET "ipv4/ip_forward";
31 else if (af == LLDPD_AF_IPV6)
32 fname = PROCFS_SYS_NET "ipv6/conf/all/forwarding";
33 else
34 return -1;
35
8b549648 36 if ((fd = priv_open(fname)) < 0) return -1;
1cf1a23f 37
8b549648 38 if (read(fd, &status, 1) == 1) rc = (status == '1');
1cf1a23f
AQ
39
40 close(fd);
41 return rc;
42}
43
c3e340b6 44int
8b549648
VB
45interfaces_routing_enabled(struct lldpd *cfg)
46{
c3e340b6 47 (void)cfg;
c3e340b6 48 int rc;
1cf1a23f
AQ
49
50 rc = ip_forwarding_enabled(LLDPD_AF_IPV4);
51 /*
52 * Report being a router if IPv4 forwarding is enabled.
53 * In case of error also stop the execution right away.
54 * If IPv4 forwarding is disabled we'll check the IPv6 status.
55 */
8b549648 56 if (rc != 0) return rc;
1cf1a23f
AQ
57
58 return ip_forwarding_enabled(LLDPD_AF_IPV6);
c3e340b6 59}