Codebase list lldpd / cd0cb19
Update upstream source from tag 'upstream/1.0.5' Update to upstream version '1.0.5' with Debian dir 7d9ecf5d788db36a5abd1444ab250ee9470dbca4 Vincent Bernat 4 years ago
71 changed file(s) with 2775 addition(s) and 543 deletion(s). Raw diff Collapse all Expand all
0 1.0.4
0 1.0.5
0 1.0.5 [2020-02-01 22:15:40 +0100]:
1
2 - [6d83fa565e82] release: 1.0.5 (Vincent Bernat)
3 - [3d65bc40a27f] include: remove in6.h from linux/bridge.h (Vincent Bernat)
4 - [69a0de1dc81a] tests: provide a Dockerfile to build with wheezy (Vincent Bernat)
5 - [0994188ff6a6] include: don't use __kernel_sa_family_t (Vincent Bernat)
6 - [e74d1f683e89] include: don't include linux/sysinfo.h (Vincent Bernat)
7 - [217b9531d405] interfaces: include "netinet/in.h" before kernel headers (Vincent Bernat)
8 - [ae03f0903509] interfaces: fix usage of inet_pton() (Vincent Bernat)
9 - [0b2e10b58220] travis: remove ARM64 (Vincent Bernat)
10 - [8b2b28f54595] interfaces: move bitmaps function to a dedicated file (Vincent Bernat)
11 - [21a0428a6ebf] snmp: additional fix around NetSNMP 5.8+ and function pointers (Vincent Bernat)
12 - [31ac51a8ef2e] snmp: tentative to fix compilation with older versions of NetSNMP (Vincent Bernat)
13 - [385e5e4cf3a7] interfaces: correctly handle bridges with VLAN filtering enabled (Vincent Bernat)
14 - [d807e90f60b8] daemon: remove unused interface types (Vincent Bernat)
15 - [24e8fda8fa36] tests: check we don't mix VLAN among interfaces (Vincent Bernat)
16 - [f9e522d6cf2c] snmp: update signature for create_ostring (Vincent Bernat)
17 - [f27e002f6993] snmp: update signature of fmtaddr and send functions (Vincent Bernat)
18 - [98282043df36] debian: update watch file (Vincent Bernat)
19 - [33a2f0f2eaf0] Merge pull request #376 from stannous/remote-vlan-limitations (Vincent Bernat)
20 - [cf6d726e9057] tests: use "-Ln" to avoid logging with snmpd (Vincent Bernat)
21 - [0c5525bbef50] netlink: fix detection of VLAN 1 (Vincent Bernat)
22 - [b2e80798d1fc] netlink: use an optimized version of num_bits_set (Vincent Bernat)
23 - [626ea3610fa3] interfaces: fix for limitation of 10 VLANs for LLDP .1q feature (Radhika Mahankali)
24 - [6f66d1086b11] lib: don't break ABI by moving new config_tx_interval_ms to end (Vincent Bernat)
25 - [4491a5cc42b2] Merge pull request #379 from jp-t/master (Vincent Bernat)
26 - [5134d8882312] lldpd: set a 30 seconds lower limit to the safeguard timer (Jean-Pierre Tosoni)
27 - [6ef305d50c07] doc, tests: milliseconds tx-interval finishing touch (Jean-Pierre Tosoni)
28 - [7f6a8ace68b5] snmp agent: fix tests suite for milliseconds units (Jean-Pierre Tosoni)
29 - [74f55c2e029d] Allow configuring tx-interval in milliseconds (Jean-Pierre Tosoni)
30 - [b2bd6c456edc] tests: remove hack around libtool on OSX (Vincent Bernat)
31 - [cbafbacca083] tests: skip tests requiring kernel features not present (Vincent Bernat)
32 - [60c22a3c3180] travis: update to Bionic (Vincent Bernat)
33 - [1f2e7757828c] travis: also build for arm64 (Vincent Bernat)
34 - [036fca466fc7] Merge pull request #375 from stannous/master (Vincent Bernat)
35 - [e512429c88d2] Fix for LLDP related netlink error messages (Radhika Mahankali)
36 - [e02913c2c5a3] Revert "client: remove useless variable declaration in zsh completion" (Vincent Bernat)
37 - [8e857e1b2044] client: fix zsh completion to not alter global environment (Vincent Bernat)
38 - [e37dd8d0a3f6] client: remove useless variable declaration in zsh completion (Vincent Bernat)
39 - [3ae837fd06da] LLDPD should document system refresh timer (tx-interval * 20) (Sam Tannous)
40 - [314ca2736599] lldp: don't discard the whole LLDPDU when only one TLV is invalid (Vincent Bernat)
41 - [69362215b2fb] tests: add a test with different MTU interfaces (Vincent Bernat)
42 - [70845fe4e73b] redhat: fix license name in spec file (Vincent Bernat)
43 - [9c49cedf8e75] lib: fix memory leak when handling I/O (Vincent Bernat)
44 - [7056d802b9c5] lldpcli: ask for power pairs only when PSE (Vincent Bernat)
45 - [990e4e384315] Merge pull request #350 from patrikdanielssonaxis/8023bt (Vincent Bernat)
46 - [d88003ff0288] test: add tests for 802.3BT additions (Vincent Bernat)
47 - [ece1209a900f] test: use scapy when sending pcap files (Vincent Bernat)
48 - [7cfcd3b7efb9] lldp: Power via MDI TLV: Initial support for 802.3bt (Patrik Danielsson)
49 - [92e3b3ac3199] Merge branch 'feature/vlan-enabled-bridge' (Vincent Bernat)
50 - [a9fe956f3e07] lldp: when receiving a shutdown LLDPU, don't clear chassis information (Vincent Bernat)
51 - [3aeae72b9771] lldp: validate a bit more received LLDP frames (Vincent Bernat)
52 - [fc5526dae75f] interfaces: only register protocol handler for LLDP when only LLDP enabled (Vincent Bernat)
53 - [fc8164d80bc9] lldpctl: don't reopen control socket each time we want to lock (Vincent Bernat)
54 - [0a46b330f02b] lldpctl: put a lock around some commands to avoid race conditions (Vincent Bernat)
55 - [5c969283279e] log: don't use black for coloring DBG (Vincent Bernat)
56 - [011056b3a714] netlink: support VLAN-aware bridges (Vincent Bernat)
57 - [5a85fbc93433] netlink: ignore IFLA_LINK if we previously received IFLA_LINK_NETNSID (Vincent Bernat)
58 - [43b333967018] interfaces: don't log errno when detecting loops (Vincent Bernat)
59 - [11df89a99dae] tests: fix skip instruction (Vincent Bernat)
60 - [f6bbc43b2085] tests: don't use pytest.config (Vincent Bernat)
61 - [68bc4a4d6293] interfaces: enable matching on interface name for management address (Vincent Bernat)
62 - [d94afe74b665] lldpd: fix bitfield (Wataru Ashihara)
63 - [92014c586860] client: fix parameter order (Wataru Ashihara)
64 - [a32224491a62] lib: fix memory leak (Wataru Ashihara)
65 - [07ecfcd1972e] fix typo (Wataru Ashihara)
66 - [c3cb7055c02d] lib: fix enumeration (Wataru Ashihara)
67 - [9b68a67f5dae] build: disable warnings on cast alignments (Vincent Bernat)
68 - [27ea4d1e7e1d] tests: be verbose when running make on CI when an error happens (Vincent Bernat)
69 - [30fca74bf43f] client: don't display management interface index if unknown (Vincent Bernat)
70 - [b7b7dc349aa4] interfaces: compute interface index for fixed management address (Vincent Bernat)
71 - [d319b0deaccf] lib: expose management interface index (Vincent Bernat)
72 - [db76b2281622] lib: fix missing words in lldpctl.h (Vincent Bernat)
73 - [a192a2e91f81] include: update headers to 4.19 (Vincent Bernat)
74 - [869ab1032650] June 15th 2019 was a Saturday, not a Sunday (eb3095)
75 - [d3fa9b099783] osx: update recipe for HomeBrew (Vincent Bernat)
76
077 1.0.4 [2019-06-15 11:09:44 +0200]:
178
279 - [1507a0035694] release: 1.0.4 (Vincent Bernat)
0 lldpd (1.0.5)
1 * Changes:
2 + Interface names are also matched for management addresses.
3 + On Linux, only register protocol handler for LLDP when only LLDP
4 is enabled.
5 + Stricter on LLDP incoming frames validation.
6 + Add support for VLAN-aware bridges for Linux (no range support).
7 + Add support for 802.3BT (no SNMP support).
8 + Add support for millisecond-grained tx-interval (Jean-Pierre Tosoni).
9 + Use generic names for VLAN names, instead of interface names (eg
10 vlan100 instead of eth1.100).
11 * Fix:
12 + Don't clear chassis TLV on shutdown LLDPDU.
13 + Don't require/display powerpairs for Dot3 power when device type
14 is PD.
15
016 lldpd (1.0.4)
117 * Changes:
218 + Add "configure system max-neighbors XX" command to modify maximum
00 #! /bin/sh
11 # Guess values for system-dependent variables and create Makefiles.
2 # Generated by GNU Autoconf 2.69 for lldpd 1.0.4.
2 # Generated by GNU Autoconf 2.69 for lldpd 1.0.5.
33 #
44 # Report bugs to <https://github.com/vincentbernat/lldpd/issues>.
55 #
589589 # Identity of this package.
590590 PACKAGE_NAME='lldpd'
591591 PACKAGE_TARNAME='lldpd'
592 PACKAGE_VERSION='1.0.4'
593 PACKAGE_STRING='lldpd 1.0.4'
592 PACKAGE_VERSION='1.0.5'
593 PACKAGE_STRING='lldpd 1.0.5'
594594 PACKAGE_BUGREPORT='https://github.com/vincentbernat/lldpd/issues'
595595 PACKAGE_URL='http://vincentbernat.github.io/lldpd/'
596596
15161516 # Omit some internal or obsolete options to make the list less imposing.
15171517 # This message is too long to be a string in the A/UX 3.1 sh.
15181518 cat <<_ACEOF
1519 \`configure' configures lldpd 1.0.4 to adapt to many kinds of systems.
1519 \`configure' configures lldpd 1.0.5 to adapt to many kinds of systems.
15201520
15211521 Usage: $0 [OPTION]... [VAR=VALUE]...
15221522
15871587
15881588 if test -n "$ac_init_help"; then
15891589 case $ac_init_help in
1590 short | recursive ) echo "Configuration of lldpd 1.0.4:";;
1590 short | recursive ) echo "Configuration of lldpd 1.0.5:";;
15911591 esac
15921592 cat <<\_ACEOF
15931593
18041804 test -n "$ac_init_help" && exit $ac_status
18051805 if $ac_init_version; then
18061806 cat <<\_ACEOF
1807 lldpd configure 1.0.4
1807 lldpd configure 1.0.5
18081808 generated by GNU Autoconf 2.69
18091809
18101810 Copyright (C) 2012 Free Software Foundation, Inc.
22842284 This file contains any messages produced by compilers while
22852285 running configure, to aid debugging if configure makes a mistake.
22862286
2287 It was created by lldpd $as_me 1.0.4, which was
2287 It was created by lldpd $as_me 1.0.5, which was
22882288 generated by GNU Autoconf 2.69. Invocation command line was
22892289
22902290 $ $0 $@
31583158
31593159 # Define the identity of the package.
31603160 PACKAGE='lldpd'
3161 VERSION='1.0.4'
3161 VERSION='1.0.5'
31623162
31633163
31643164 cat >>confdefs.h <<_ACEOF
1638516385 ;;
1638616386 esac
1638716387
16388 { $as_echo "$as_me:${as_lineno-$LINENO}: checking CFLAGS for gcc -Wcast-align" >&5
16389 $as_echo_n "checking CFLAGS for gcc -Wcast-align... " >&6; }
16390 if ${ac_cv_cflags_gcc_option__Wcast_align+:} false; then :
16391 $as_echo_n "(cached) " >&6
16392 else
16393 ac_cv_cflags_gcc_option__Wcast_align="no, unknown"
16394
16395 ac_ext=c
16396 ac_cpp='$CPP $CPPFLAGS'
16397 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
16398 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
16399 ac_compiler_gnu=$ac_cv_c_compiler_gnu
16400
16401 ac_save_CFLAGS="$CFLAGS"
16402 for ac_arg in "-pedantic -Werror % -Wcast-align" "-pedantic % -Wcast-align %% no, obsolete" #
16403 do CFLAGS="$ac_save_CFLAGS $LLDP_CFLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
16404 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
16405 /* end confdefs.h. */
16406
16407 int
16408 main ()
16409 {
16410 return 0;
16411 ;
16412 return 0;
16413 }
16414 _ACEOF
16415 if ac_fn_c_try_compile "$LINENO"; then :
16416 ac_cv_cflags_gcc_option__Wcast_align=`echo $ac_arg | sed -e 's,.*% *,,'` ; break
16417 fi
16418 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
16419 done
16420 CFLAGS="$ac_save_CFLAGS"
16421 ac_ext=c
16422 ac_cpp='$CPP $CPPFLAGS'
16423 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
16424 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
16425 ac_compiler_gnu=$ac_cv_c_compiler_gnu
16426
16427
16428 fi
16429 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cflags_gcc_option__Wcast_align" >&5
16430 $as_echo "$ac_cv_cflags_gcc_option__Wcast_align" >&6; }
16431 ac_res=$ac_cv_cflags_gcc_option__Wcast_align
16432 case ".${ac_res}" in
16433 .ok|.ok,*) ;;
16434 .|.no|.no,*) ;;
16435 *)
16436 if echo " $LLDP_CFLAGS " | grep " ${ac_res} " 2>&1 >/dev/null
16437 then { { $as_echo "$as_me:${as_lineno-$LINENO}: : LLDP_CFLAGS does contain \${ac_res}"; } >&5
16438 (: LLDP_CFLAGS does contain ${ac_res}) 2>&5
16439 ac_status=$?
16440 $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
16441 test $ac_status = 0; }
16442 else { { $as_echo "$as_me:${as_lineno-$LINENO}: : LLDP_CFLAGS=\"\$LLDP_CFLAGS \${ac_res}\""; } >&5
16443 (: LLDP_CFLAGS="$LLDP_CFLAGS ${ac_res}") 2>&5
16444 ac_status=$?
16445 $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
16446 test $ac_status = 0; }
16447 LLDP_CFLAGS="$LLDP_CFLAGS ${ac_res}"
16448 fi
16449 ;;
16450 esac
16451
1645216388 { $as_echo "$as_me:${as_lineno-$LINENO}: checking CFLAGS for gcc -Wheader-guard" >&5
1645316389 $as_echo_n "checking CFLAGS for gcc -Wheader-guard... " >&6; }
1645416390 if ${ac_cv_cflags_gcc_option__Wheader_guard+:} false; then :
1676916705 ;;
1677016706 esac
1677116707
16772 { $as_echo "$as_me:${as_lineno-$LINENO}: checking CFLAGS for gcc -Wno-unused-parameter" >&5
16708 { $as_echo "$as_me:${as_lineno-$LINENO}: checking CFLAGS for gcc -Wno-cast-align" >&5
16709 $as_echo_n "checking CFLAGS for gcc -Wno-cast-align... " >&6; }
16710 if ${ac_cv_cflags_gcc_option__Wno_cast_align+:} false; then :
16711 $as_echo_n "(cached) " >&6
16712 else
16713 ac_cv_cflags_gcc_option__Wno_cast_align="no, unknown"
16714
16715 ac_ext=c
16716 ac_cpp='$CPP $CPPFLAGS'
16717 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
16718 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
16719 ac_compiler_gnu=$ac_cv_c_compiler_gnu
16720
16721 ac_save_CFLAGS="$CFLAGS"
16722 for ac_arg in "-pedantic -Werror % -Wno-cast-align" "-pedantic % -Wno-cast-align %% no, obsolete" #
16723 do CFLAGS="$ac_save_CFLAGS $LLDP_CFLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
16724 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
16725 /* end confdefs.h. */
16726
16727 int
16728 main ()
16729 {
16730 return 0;
16731 ;
16732 return 0;
16733 }
16734 _ACEOF
16735 if ac_fn_c_try_compile "$LINENO"; then :
16736 ac_cv_cflags_gcc_option__Wno_cast_align=`echo $ac_arg | sed -e 's,.*% *,,'` ; break
16737 fi
16738 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
16739 done
16740 CFLAGS="$ac_save_CFLAGS"
16741 ac_ext=c
16742 ac_cpp='$CPP $CPPFLAGS'
16743 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
16744 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
16745 ac_compiler_gnu=$ac_cv_c_compiler_gnu
16746
16747
16748 fi
16749 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cflags_gcc_option__Wno_cast_align" >&5
16750 $as_echo "$ac_cv_cflags_gcc_option__Wno_cast_align" >&6; }
16751 ac_res=$ac_cv_cflags_gcc_option__Wno_cast_align
16752 case ".${ac_res}" in
16753 .ok|.ok,*) ;;
16754 .|.no|.no,*) ;;
16755 *)
16756 if echo " $LLDP_CFLAGS " | grep " ${ac_res} " 2>&1 >/dev/null
16757 then { { $as_echo "$as_me:${as_lineno-$LINENO}: : LLDP_CFLAGS does contain \${ac_res}"; } >&5
16758 (: LLDP_CFLAGS does contain ${ac_res}) 2>&5
16759 ac_status=$?
16760 $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
16761 test $ac_status = 0; }
16762 else { { $as_echo "$as_me:${as_lineno-$LINENO}: : LLDP_CFLAGS=\"\$LLDP_CFLAGS \${ac_res}\""; } >&5
16763 (: LLDP_CFLAGS="$LLDP_CFLAGS ${ac_res}") 2>&5
16764 ac_status=$?
16765 $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
16766 test $ac_status = 0; }
16767 LLDP_CFLAGS="$LLDP_CFLAGS ${ac_res}"
16768 fi
16769 ;;
16770 esac
16771 { $as_echo "$as_me:${as_lineno-$LINENO}: checking CFLAGS for gcc -Wno-unused-parameter" >&5
1677316772 $as_echo_n "checking CFLAGS for gcc -Wno-unused-parameter... " >&6; }
1677416773 if ${ac_cv_cflags_gcc_option__Wno_unused_parameter+:} false; then :
1677516774 $as_echo_n "(cached) " >&6
2306123060 # report actual input values of CONFIG_FILES etc. instead of their
2306223061 # values after options handling.
2306323062 ac_log="
23064 This file was extended by lldpd $as_me 1.0.4, which was
23063 This file was extended by lldpd $as_me 1.0.5, which was
2306523064 generated by GNU Autoconf 2.69. Invocation command line was
2306623065
2306723066 CONFIG_FILES = $CONFIG_FILES
2312823127 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
2312923128 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
2313023129 ac_cs_version="\\
23131 lldpd config.status 1.0.4
23130 lldpd config.status 1.0.5
2313223131 configured by $0, generated by GNU Autoconf 2.69,
2313323132 with options \\"\$ac_cs_config\\"
2313423133
7777 AX_CFLAGS_GCC_OPTION([-Wformat-security], [LLDP_CFLAGS])
7878 AX_CFLAGS_GCC_OPTION([-Wimplicit-fallthrough], [LLDP_CFLAGS])
7979 AX_CFLAGS_GCC_OPTION([-Wfatal-errors], [LLDP_CFLAGS])
80 AX_CFLAGS_GCC_OPTION([-Wcast-align], [LLDP_CFLAGS])
8180 AX_CFLAGS_GCC_OPTION([-Wheader-guard], [LLDP_CFLAGS])
8281 AX_CFLAGS_GCC_OPTION([-Wdocumentation], [LLDP_CFLAGS])
8382 AX_CFLAGS_GCC_OPTION([-Winline], [LLDP_CFLAGS])
8483 AX_CFLAGS_GCC_OPTION([-Wpointer-arith], [LLDP_CFLAGS])
8584 AX_CFLAGS_GCC_OPTION([-fno-omit-frame-pointer], [LLDP_CFLAGS])
85 AX_CFLAGS_GCC_OPTION([-Wno-cast-align], [LLDP_CFLAGS]) dnl clang is bad at this
8686 AX_CFLAGS_GCC_OPTION([-Wno-unused-parameter], [LLDP_CFLAGS])
8787 AX_CFLAGS_GCC_OPTION([-Wno-missing-field-initializers], [LLDP_CFLAGS])
8888 AX_CFLAGS_GCC_OPTION([-Wno-sign-compare], [LLDP_CFLAGS]) dnl Should be fixed later
0 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1 #ifndef __LINUX_BPF_COMMON_H__
2 #define __LINUX_BPF_COMMON_H__
3
4 /* Instruction classes */
5 #define BPF_CLASS(code) ((code) & 0x07)
6 #define BPF_LD 0x00
7 #define BPF_LDX 0x01
8 #define BPF_ST 0x02
9 #define BPF_STX 0x03
10 #define BPF_ALU 0x04
11 #define BPF_JMP 0x05
12 #define BPF_RET 0x06
13 #define BPF_MISC 0x07
14
15 /* ld/ldx fields */
16 #define BPF_SIZE(code) ((code) & 0x18)
17 #define BPF_W 0x00 /* 32-bit */
18 #define BPF_H 0x08 /* 16-bit */
19 #define BPF_B 0x10 /* 8-bit */
20 /* eBPF BPF_DW 0x18 64-bit */
21 #define BPF_MODE(code) ((code) & 0xe0)
22 #define BPF_IMM 0x00
23 #define BPF_ABS 0x20
24 #define BPF_IND 0x40
25 #define BPF_MEM 0x60
26 #define BPF_LEN 0x80
27 #define BPF_MSH 0xa0
28
29 /* alu/jmp fields */
30 #define BPF_OP(code) ((code) & 0xf0)
31 #define BPF_ADD 0x00
32 #define BPF_SUB 0x10
33 #define BPF_MUL 0x20
34 #define BPF_DIV 0x30
35 #define BPF_OR 0x40
36 #define BPF_AND 0x50
37 #define BPF_LSH 0x60
38 #define BPF_RSH 0x70
39 #define BPF_NEG 0x80
40 #define BPF_MOD 0x90
41 #define BPF_XOR 0xa0
42
43 #define BPF_JA 0x00
44 #define BPF_JEQ 0x10
45 #define BPF_JGT 0x20
46 #define BPF_JGE 0x30
47 #define BPF_JSET 0x40
48 #define BPF_SRC(code) ((code) & 0x08)
49 #define BPF_K 0x00
50 #define BPF_X 0x08
51
52 #ifndef BPF_MAXINSNS
53 #define BPF_MAXINSNS 4096
54 #endif
55
56 #endif /* __LINUX_BPF_COMMON_H__ */
0 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
01 /*
12 * ethtool.h: Defines for Linux ethtool.
23 *
910 * Portions Copyright (C) Sun Microsystems 2008
1011 */
1112
12 #ifndef _UAPI_LINUX_ETHTOOL_H
13 #define _UAPI_LINUX_ETHTOOL_H
14
13 #ifndef _LINUX_ETHTOOL_H
14 #define _LINUX_ETHTOOL_H
15
16 #include <linux/kernel.h>
1517 #include <linux/types.h>
1618 #include <linux/if_ether.h>
1719
18 #ifndef __KERNEL__
1920 #include <limits.h> /* for INT_MAX */
20 #endif
2121
2222 /* All structures exposed to userland should be defined such that they
2323 * have the same layout for 32-bit and 64-bit userland.
114114 __u32 reserved[2];
115115 };
116116
117 static inline void ethtool_cmd_speed_set(struct ethtool_cmd *ep,
117 static __inline__ void ethtool_cmd_speed_set(struct ethtool_cmd *ep,
118118 __u32 speed)
119119 {
120120 ep->speed = (__u16)(speed & 0xFFFF);
121121 ep->speed_hi = (__u16)(speed >> 16);
122122 }
123123
124 static inline __u32 ethtool_cmd_speed(const struct ethtool_cmd *ep)
124 static __inline__ __u32 ethtool_cmd_speed(const struct ethtool_cmd *ep)
125125 {
126126 return (ep->speed_hi << 16) | ep->speed;
127127 }
214214 __u32 data;
215215 };
216216
217 #define PFC_STORM_PREVENTION_AUTO 0xffff
218 #define PFC_STORM_PREVENTION_DISABLE 0
219
217220 enum tunable_id {
218221 ETHTOOL_ID_UNSPEC,
219222 ETHTOOL_RX_COPYBREAK,
220223 ETHTOOL_TX_COPYBREAK,
224 ETHTOOL_PFC_PREVENTION_TOUT, /* timeout in msecs */
221225 /*
222 * Add your fresh new tubale attribute above and remember to update
226 * Add your fresh new tunable attribute above and remember to update
223227 * tunable_strings[] in net/core/ethtool.c
224228 */
225229 __ETHTOOL_TUNABLE_COUNT,
863867 * includes the %FLOW_EXT or %FLOW_MAC_EXT flag
864868 * (see &struct ethtool_flow_ext description).
865869 * @ring_cookie: RX ring/queue index to deliver to, or %RX_CLS_FLOW_DISC
866 * if packets should be discarded
870 * if packets should be discarded, or %RX_CLS_FLOW_WAKE if the
871 * packets should be used for Wake-on-LAN with %WAKE_FILTER
867872 * @location: Location of rule in the table. Locations must be
868873 * numbered such that a flow matching multiple rules will be
869874 * classified according to the first (lowest numbered) rule.
892897 #define ETHTOOL_RX_FLOW_SPEC_RING 0x00000000FFFFFFFFLL
893898 #define ETHTOOL_RX_FLOW_SPEC_RING_VF 0x000000FF00000000LL
894899 #define ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF 32
895 static inline __u64 ethtool_get_flow_spec_ring(__u64 ring_cookie)
900 static __inline__ __u64 ethtool_get_flow_spec_ring(__u64 ring_cookie)
896901 {
897902 return ETHTOOL_RX_FLOW_SPEC_RING & ring_cookie;
898 };
899
900 static inline __u64 ethtool_get_flow_spec_ring_vf(__u64 ring_cookie)
903 }
904
905 static __inline__ __u64 ethtool_get_flow_spec_ring_vf(__u64 ring_cookie)
901906 {
902907 return (ETHTOOL_RX_FLOW_SPEC_RING_VF & ring_cookie) >>
903908 ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
904 };
909 }
905910
906911 /**
907912 * struct ethtool_rxnfc - command to get or set RX flow classification rules
911916 * @flow_type: Type of flow to be affected, e.g. %TCP_V4_FLOW
912917 * @data: Command-dependent value
913918 * @fs: Flow classification rule
919 * @rss_context: RSS context to be affected
914920 * @rule_cnt: Number of rules to be affected
915921 * @rule_locs: Array of used rule locations
916922 *
917923 * For %ETHTOOL_GRXFH and %ETHTOOL_SRXFH, @data is a bitmask indicating
918924 * the fields included in the flow hash, e.g. %RXH_IP_SRC. The following
919 * structure fields must not be used.
925 * structure fields must not be used, except that if @flow_type includes
926 * the %FLOW_RSS flag, then @rss_context determines which RSS context to
927 * act on.
920928 *
921929 * For %ETHTOOL_GRXRINGS, @data is set to the number of RX rings/queues
922930 * on return.
928936 * set in @data then special location values should not be used.
929937 *
930938 * For %ETHTOOL_GRXCLSRULE, @fs.@location specifies the location of an
931 * existing rule on entry and @fs contains the rule on return.
939 * existing rule on entry and @fs contains the rule on return; if
940 * @fs.@flow_type includes the %FLOW_RSS flag, then @rss_context is
941 * filled with the RSS context ID associated with the rule.
932942 *
933943 * For %ETHTOOL_GRXCLSRLALL, @rule_cnt specifies the array size of the
934944 * user buffer for @rule_locs on entry. On return, @data is the size
939949 * For %ETHTOOL_SRXCLSRLINS, @fs specifies the rule to add or update.
940950 * @fs.@location either specifies the location to use or is a special
941951 * location value with %RX_CLS_LOC_SPECIAL flag set. On return,
942 * @fs.@location is the actual rule location.
952 * @fs.@location is the actual rule location. If @fs.@flow_type
953 * includes the %FLOW_RSS flag, @rss_context is the RSS context ID to
954 * use for flow spreading traffic which matches this rule. The value
955 * from the rxfh indirection table will be added to @fs.@ring_cookie
956 * to choose which ring to deliver to.
943957 *
944958 * For %ETHTOOL_SRXCLSRLDEL, @fs.@location specifies the location of an
945959 * existing rule on entry.
960974 __u32 flow_type;
961975 __u64 data;
962976 struct ethtool_rx_flow_spec fs;
963 __u32 rule_cnt;
977 union {
978 __u32 rule_cnt;
979 __u32 rss_context;
980 };
964981 __u32 rule_locs[0];
965982 };
966983
9871004 /**
9881005 * struct ethtool_rxfh - command to get/set RX flow hash indir or/and hash key.
9891006 * @cmd: Specific command number - %ETHTOOL_GRSSH or %ETHTOOL_SRSSH
990 * @rss_context: RSS context identifier.
1007 * @rss_context: RSS context identifier. Context 0 is the default for normal
1008 * traffic; other contexts can be referenced as the destination for RX flow
1009 * classification rules. %ETH_RXFH_CONTEXT_ALLOC is used with command
1010 * %ETHTOOL_SRSSH to allocate a new RSS context; on return this field will
1011 * contain the ID of the newly allocated context.
9911012 * @indir_size: On entry, the array size of the user buffer for the
9921013 * indirection table, which may be zero, or (for %ETHTOOL_SRSSH),
9931014 * %ETH_RXFH_INDIR_NO_CHANGE. On return from %ETHTOOL_GRSSH,
10061027 * size should be returned. For %ETHTOOL_SRSSH, an @indir_size of
10071028 * %ETH_RXFH_INDIR_NO_CHANGE means that indir table setting is not requested
10081029 * and a @indir_size of zero means the indir table should be reset to default
1009 * values. An hfunc of zero means that hash function setting is not requested.
1030 * values (if @rss_context == 0) or that the RSS context should be deleted.
1031 * An hfunc of zero means that hash function setting is not requested.
10101032 */
10111033 struct ethtool_rxfh {
10121034 __u32 cmd;
10181040 __u32 rsvd32;
10191041 __u32 rss_config[0];
10201042 };
1043 #define ETH_RXFH_CONTEXT_ALLOC 0xffffffff
10211044 #define ETH_RXFH_INDIR_NO_CHANGE 0xffffffff
10221045
10231046 /**
12221245
12231246 #define MAX_NUM_QUEUE 4096
12241247
1225 #if 0
12261248 /**
12271249 * struct ethtool_per_queue_op - apply sub command to the queues in mask.
12281250 * @cmd: ETHTOOL_PERQUEUE
12361258 __u32 queue_mask[__KERNEL_DIV_ROUND_UP(MAX_NUM_QUEUE, 32)];
12371259 char data[];
12381260 };
1239 #endif
1261
1262 /**
1263 * struct ethtool_fecparam - Ethernet forward error correction(fec) parameters
1264 * @cmd: Command number = %ETHTOOL_GFECPARAM or %ETHTOOL_SFECPARAM
1265 * @active_fec: FEC mode which is active on porte
1266 * @fec: Bitmask of supported/configured FEC modes
1267 * @rsvd: Reserved for future extensions. i.e FEC bypass feature.
1268 *
1269 * Drivers should reject a non-zero setting of @autoneg when
1270 * autoneogotiation is disabled (or not supported) for the link.
1271 *
1272 */
1273 struct ethtool_fecparam {
1274 __u32 cmd;
1275 /* bitmask of FEC modes */
1276 __u32 active_fec;
1277 __u32 fec;
1278 __u32 reserved;
1279 };
1280
1281 /**
1282 * enum ethtool_fec_config_bits - flags definition of ethtool_fec_configuration
1283 * @ETHTOOL_FEC_NONE: FEC mode configuration is not supported
1284 * @ETHTOOL_FEC_AUTO: Default/Best FEC mode provided by driver
1285 * @ETHTOOL_FEC_OFF: No FEC Mode
1286 * @ETHTOOL_FEC_RS: Reed-Solomon Forward Error Detection mode
1287 * @ETHTOOL_FEC_BASER: Base-R/Reed-Solomon Forward Error Detection mode
1288 */
1289 enum ethtool_fec_config_bits {
1290 ETHTOOL_FEC_NONE_BIT,
1291 ETHTOOL_FEC_AUTO_BIT,
1292 ETHTOOL_FEC_OFF_BIT,
1293 ETHTOOL_FEC_RS_BIT,
1294 ETHTOOL_FEC_BASER_BIT,
1295 };
1296
1297 #define ETHTOOL_FEC_NONE (1 << ETHTOOL_FEC_NONE_BIT)
1298 #define ETHTOOL_FEC_AUTO (1 << ETHTOOL_FEC_AUTO_BIT)
1299 #define ETHTOOL_FEC_OFF (1 << ETHTOOL_FEC_OFF_BIT)
1300 #define ETHTOOL_FEC_RS (1 << ETHTOOL_FEC_RS_BIT)
1301 #define ETHTOOL_FEC_BASER (1 << ETHTOOL_FEC_BASER_BIT)
12401302
12411303 /* CMDs currently supported */
12421304 #define ETHTOOL_GSET 0x00000001 /* DEPRECATED, Get settings.
13301392 #define ETHTOOL_SLINKSETTINGS 0x0000004d /* Set ethtool_link_settings */
13311393 #define ETHTOOL_PHY_GTUNABLE 0x0000004e /* Get PHY tunable configuration */
13321394 #define ETHTOOL_PHY_STUNABLE 0x0000004f /* Set PHY tunable configuration */
1395 #define ETHTOOL_GFECPARAM 0x00000050 /* Get FEC settings */
1396 #define ETHTOOL_SFECPARAM 0x00000051 /* Set FEC settings */
13331397
13341398 /* compatibility with older code */
13351399 #define SPARC_ETH_GSET ETHTOOL_GSET
13841448 ETHTOOL_LINK_MODE_10000baseLR_Full_BIT = 44,
13851449 ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT = 45,
13861450 ETHTOOL_LINK_MODE_10000baseER_Full_BIT = 46,
1387
1451 ETHTOOL_LINK_MODE_2500baseT_Full_BIT = 47,
1452 ETHTOOL_LINK_MODE_5000baseT_Full_BIT = 48,
1453
1454 ETHTOOL_LINK_MODE_FEC_NONE_BIT = 49,
1455 ETHTOOL_LINK_MODE_FEC_RS_BIT = 50,
1456 ETHTOOL_LINK_MODE_FEC_BASER_BIT = 51,
13881457
13891458 /* Last allowed bit for __ETHTOOL_LINK_MODE_LEGACY_MASK is bit
13901459 * 31. Please do NOT define any SUPPORTED_* or ADVERTISED_*
13931462 */
13941463
13951464 __ETHTOOL_LINK_MODE_LAST
1396 = ETHTOOL_LINK_MODE_10000baseER_Full_BIT,
1465 = ETHTOOL_LINK_MODE_FEC_BASER_BIT,
13971466 };
13981467
13991468 #define __ETHTOOL_LINK_MODE_LEGACY_MASK(base_name) \
14841553 * it was forced up into this mode or autonegotiated.
14851554 */
14861555
1487 /* The forced speed, in units of 1Mb. All values 0 to INT_MAX are legal. */
1556 /* The forced speed, in units of 1Mb. All values 0 to INT_MAX are legal.
1557 * Update drivers/net/phy/phy.c:phy_speed_to_str() and
1558 * drivers/net/bonding/bond_3ad.c:__get_link_speed() when adding new values.
1559 */
14881560 #define SPEED_10 10
14891561 #define SPEED_100 100
14901562 #define SPEED_1000 1000
14911563 #define SPEED_2500 2500
14921564 #define SPEED_5000 5000
14931565 #define SPEED_10000 10000
1566 #define SPEED_14000 14000
14941567 #define SPEED_20000 20000
14951568 #define SPEED_25000 25000
14961569 #define SPEED_40000 40000
15001573
15011574 #define SPEED_UNKNOWN -1
15021575
1503 static inline int ethtool_validate_speed(__u32 speed)
1576 static __inline__ int ethtool_validate_speed(__u32 speed)
15041577 {
15051578 return speed <= INT_MAX || speed == SPEED_UNKNOWN;
15061579 }
15101583 #define DUPLEX_FULL 0x01
15111584 #define DUPLEX_UNKNOWN 0xff
15121585
1513 static inline int ethtool_validate_duplex(__u8 duplex)
1586 static __inline__ int ethtool_validate_duplex(__u8 duplex)
15141587 {
15151588 switch (duplex) {
15161589 case DUPLEX_HALF:
15591632 #define WAKE_ARP (1 << 4)
15601633 #define WAKE_MAGIC (1 << 5)
15611634 #define WAKE_MAGICSECURE (1 << 6) /* only meaningful if WAKE_MAGIC */
1635 #define WAKE_FILTER (1 << 7)
15621636
15631637 /* L2-L4 network traffic flow types */
15641638 #define TCP_V4_FLOW 0x01 /* hash or spec (tcp_ip4_spec) */
15821656 /* Flag to enable additional fields in struct ethtool_rx_flow_spec */
15831657 #define FLOW_EXT 0x80000000
15841658 #define FLOW_MAC_EXT 0x40000000
1659 /* Flag to enable RSS spreading of traffic matching rule (nfc only) */
1660 #define FLOW_RSS 0x20000000
15851661
15861662 /* L3-L4 network traffic flow hash options */
15871663 #define RXH_L2DA (1 << 1)
15941670 #define RXH_DISCARD (1 << 31)
15951671
15961672 #define RX_CLS_FLOW_DISC 0xffffffffffffffffULL
1673 #define RX_CLS_FLOW_WAKE 0xfffffffffffffffeULL
15971674
15981675 /* Special RX classification rule insert location values */
15991676 #define RX_CLS_LOC_SPECIAL 0x80000000 /* flag */
16331710 ETH_RESET_PHY = 1 << 6, /* Transceiver/PHY */
16341711 ETH_RESET_RAM = 1 << 7, /* RAM shared between
16351712 * multiple components */
1713 ETH_RESET_AP = 1 << 8, /* Application processor */
16361714
16371715 ETH_RESET_DEDICATED = 0x0000ffff, /* All components dedicated to
16381716 * this interface */
17011779 * %ethtool_link_mode_bit_indices for the link modes, and other
17021780 * link features that the link partner advertised through
17031781 * autonegotiation; 0 if unknown or not applicable. Read-only.
1782 * @transceiver: Used to distinguish different possible PHY types,
1783 * reported consistently by PHYLIB. Read-only.
17041784 *
17051785 * If autonegotiation is disabled, the speed and @duplex represent the
17061786 * fixed link mode and are writable if the driver supports multiple
17521832 __u8 eth_tp_mdix;
17531833 __u8 eth_tp_mdix_ctrl;
17541834 __s8 link_mode_masks_nwords;
1755 __u32 reserved[8];
1835 __u8 transceiver;
1836 __u8 reserved1[3];
1837 __u32 reserved[7];
17561838 __u32 link_mode_masks[0];
17571839 /* layout of link_mode_masks fields:
17581840 * __u32 map_supported[link_mode_masks_nwords];
17601842 * __u32 map_lp_advertising[link_mode_masks_nwords];
17611843 */
17621844 };
1763 #endif /* _UAPI_LINUX_ETHTOOL_H */
1845 #endif /* _LINUX_ETHTOOL_H */
0 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
01 /*
12 * Linux Socket Filter Data Structures
23 */
67
78
89 #include <linux/types.h>
9
10 #include <linux/bpf_common.h>
1011
1112 /*
1213 * Current version of the filter code architecture.
3132 struct sock_filter *filter;
3233 };
3334
34 /*
35 * Instruction classes
36 */
37
38 #define BPF_CLASS(code) ((code) & 0x07)
39 #define BPF_LD 0x00
40 #define BPF_LDX 0x01
41 #define BPF_ST 0x02
42 #define BPF_STX 0x03
43 #define BPF_ALU 0x04
44 #define BPF_JMP 0x05
45 #define BPF_RET 0x06
46 #define BPF_MISC 0x07
47
48 /* ld/ldx fields */
49 #define BPF_SIZE(code) ((code) & 0x18)
50 #define BPF_W 0x00
51 #define BPF_H 0x08
52 #define BPF_B 0x10
53 #define BPF_MODE(code) ((code) & 0xe0)
54 #define BPF_IMM 0x00
55 #define BPF_ABS 0x20
56 #define BPF_IND 0x40
57 #define BPF_MEM 0x60
58 #define BPF_LEN 0x80
59 #define BPF_MSH 0xa0
60
61 /* alu/jmp fields */
62 #define BPF_OP(code) ((code) & 0xf0)
63 #define BPF_ADD 0x00
64 #define BPF_SUB 0x10
65 #define BPF_MUL 0x20
66 #define BPF_DIV 0x30
67 #define BPF_OR 0x40
68 #define BPF_AND 0x50
69 #define BPF_LSH 0x60
70 #define BPF_RSH 0x70
71 #define BPF_NEG 0x80
72 #define BPF_JA 0x00
73 #define BPF_JEQ 0x10
74 #define BPF_JGT 0x20
75 #define BPF_JGE 0x30
76 #define BPF_JSET 0x40
77 #define BPF_SRC(code) ((code) & 0x08)
78 #define BPF_K 0x00
79 #define BPF_X 0x08
80
8135 /* ret - BPF_K and BPF_X also apply */
8236 #define BPF_RVAL(code) ((code) & 0x18)
8337 #define BPF_A 0x10
8640 #define BPF_MISCOP(code) ((code) & 0xf8)
8741 #define BPF_TAX 0x00
8842 #define BPF_TXA 0x80
89
90 #ifndef BPF_MAXINSNS
91 #define BPF_MAXINSNS 4096
92 #endif
9343
9444 /*
9545 * Macros for filter block array initializers.
12373 #define SKF_AD_RXHASH 32
12474 #define SKF_AD_CPU 36
12575 #define SKF_AD_ALU_XOR_X 40
126 #define SKF_AD_MAX 44
127 #define SKF_NET_OFF (-0x100000)
128 #define SKF_LL_OFF (-0x200000)
76 #define SKF_AD_VLAN_TAG 44
77 #define SKF_AD_VLAN_TAG_PRESENT 48
78 #define SKF_AD_PAY_OFFSET 52
79 #define SKF_AD_RANDOM 56
80 #define SKF_AD_VLAN_TPID 60
81 #define SKF_AD_MAX 64
12982
83 #define SKF_NET_OFF (-0x100000)
84 #define SKF_LL_OFF (-0x200000)
85
86 #define BPF_NET_OFF SKF_NET_OFF
87 #define BPF_LL_OFF SKF_LL_OFF
13088
13189 #endif /* __LINUX_FILTER_H__ */
0 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
01 #ifndef __HDLC_IOCTL_H__
12 #define __HDLC_IOCTL_H__
23
3334 #define LMI_CCITT 3 /* ITU-T Annex A */
3435 #define LMI_CISCO 4 /* The "original" LMI, aka Gang of Four */
3536
36 typedef struct {
37 #ifndef __ASSEMBLY__
38
39 typedef struct {
3740 unsigned int clock_rate; /* bits per second */
3841 unsigned int clock_type; /* internal, external, TX-internal etc. */
3942 unsigned short loopback;
4043 } sync_serial_settings; /* V.35, V.24, X.21 */
4144
42 typedef struct {
45 typedef struct {
4346 unsigned int clock_rate; /* bits per second */
4447 unsigned int clock_type; /* internal, external, TX-internal etc. */
4548 unsigned short loopback;
7780
7881 /* PPP doesn't need any info now - supply length = 0 to ioctl */
7982
83 #endif /* __ASSEMBLY__ */
8084 #endif /* __HDLC_IOCTL_H__ */
0 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
01 /*
12 * INET An implementation of the TCP/IP protocol suite for the LINUX
23 * operating system. INET is implemented using the BSD Socket
1819 #ifndef _LINUX_IF_H
1920 #define _LINUX_IF_H
2021
22 #include <linux/libc-compat.h> /* for compatibility with glibc */
2123 #include <linux/types.h> /* for "__kernel_caddr_t" et al */
2224 #include <linux/socket.h> /* for "struct sockaddr" et al */
2325 /* for "__user" et al */
2426
27 #include <sys/socket.h> /* for struct sockaddr. */
28
29 #if __UAPI_DEF_IF_IFNAMSIZ
2530 #define IFNAMSIZ 16
31 #endif /* __UAPI_DEF_IF_IFNAMSIZ */
2632 #define IFALIASZ 256
2733 #include <linux/hdlc/ioctl.h>
2834
29 /* Standard interface flags (netdevice->flags). */
30 #define IFF_UP 0x1 /* interface is up */
31 #define IFF_BROADCAST 0x2 /* broadcast address valid */
32 #define IFF_DEBUG 0x4 /* turn on debugging */
33 #define IFF_LOOPBACK 0x8 /* is a loopback net */
34 #define IFF_POINTOPOINT 0x10 /* interface is has p-p link */
35 #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */
36 #define IFF_RUNNING 0x40 /* interface RFC2863 OPER_UP */
37 #define IFF_NOARP 0x80 /* no ARP protocol */
38 #define IFF_PROMISC 0x100 /* receive all packets */
39 #define IFF_ALLMULTI 0x200 /* receive all multicast packets*/
40
41 #define IFF_MASTER 0x400 /* master of a load balancer */
42 #define IFF_SLAVE 0x800 /* slave of a load balancer */
43
44 #define IFF_MULTICAST 0x1000 /* Supports multicast */
45
46 #define IFF_PORTSEL 0x2000 /* can set media type */
47 #define IFF_AUTOMEDIA 0x4000 /* auto media select active */
48 #define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses*/
49
50 #define IFF_LOWER_UP 0x10000 /* driver signals L1 up */
51 #define IFF_DORMANT 0x20000 /* driver signals dormant */
52
53 #define IFF_ECHO 0x40000 /* echo sent packets */
35 /* For glibc compatibility. An empty enum does not compile. */
36 #if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO != 0 || \
37 __UAPI_DEF_IF_NET_DEVICE_FLAGS != 0
38 /**
39 * enum net_device_flags - &struct net_device flags
40 *
41 * These are the &struct net_device flags, they can be set by drivers, the
42 * kernel and some can be triggered by userspace. Userspace can query and
43 * set these flags using userspace utilities but there is also a sysfs
44 * entry available for all dev flags which can be queried and set. These flags
45 * are shared for all types of net_devices. The sysfs entries are available
46 * via /sys/class/net/<dev>/flags. Flags which can be toggled through sysfs
47 * are annotated below, note that only a few flags can be toggled and some
48 * other flags are always preserved from the original net_device flags
49 * even if you try to set them via sysfs. Flags which are always preserved
50 * are kept under the flag grouping @IFF_VOLATILE. Flags which are __volatile__
51 * are annotated below as such.
52 *
53 * You should have a pretty good reason to be extending these flags.
54 *
55 * @IFF_UP: interface is up. Can be toggled through sysfs.
56 * @IFF_BROADCAST: broadcast address valid. Volatile.
57 * @IFF_DEBUG: turn on debugging. Can be toggled through sysfs.
58 * @IFF_LOOPBACK: is a loopback net. Volatile.
59 * @IFF_POINTOPOINT: interface is has p-p link. Volatile.
60 * @IFF_NOTRAILERS: avoid use of trailers. Can be toggled through sysfs.
61 * Volatile.
62 * @IFF_RUNNING: interface RFC2863 OPER_UP. Volatile.
63 * @IFF_NOARP: no ARP protocol. Can be toggled through sysfs. Volatile.
64 * @IFF_PROMISC: receive all packets. Can be toggled through sysfs.
65 * @IFF_ALLMULTI: receive all multicast packets. Can be toggled through
66 * sysfs.
67 * @IFF_MASTER: master of a load balancer. Volatile.
68 * @IFF_SLAVE: slave of a load balancer. Volatile.
69 * @IFF_MULTICAST: Supports multicast. Can be toggled through sysfs.
70 * @IFF_PORTSEL: can set media type. Can be toggled through sysfs.
71 * @IFF_AUTOMEDIA: auto media select active. Can be toggled through sysfs.
72 * @IFF_DYNAMIC: dialup device with changing addresses. Can be toggled
73 * through sysfs.
74 * @IFF_LOWER_UP: driver signals L1 up. Volatile.
75 * @IFF_DORMANT: driver signals dormant. Volatile.
76 * @IFF_ECHO: echo sent packets. Volatile.
77 */
78 enum net_device_flags {
79 /* for compatibility with glibc net/if.h */
80 #if __UAPI_DEF_IF_NET_DEVICE_FLAGS
81 IFF_UP = 1<<0, /* sysfs */
82 IFF_BROADCAST = 1<<1, /* __volatile__ */
83 IFF_DEBUG = 1<<2, /* sysfs */
84 IFF_LOOPBACK = 1<<3, /* __volatile__ */
85 IFF_POINTOPOINT = 1<<4, /* __volatile__ */
86 IFF_NOTRAILERS = 1<<5, /* sysfs */
87 IFF_RUNNING = 1<<6, /* __volatile__ */
88 IFF_NOARP = 1<<7, /* sysfs */
89 IFF_PROMISC = 1<<8, /* sysfs */
90 IFF_ALLMULTI = 1<<9, /* sysfs */
91 IFF_MASTER = 1<<10, /* __volatile__ */
92 IFF_SLAVE = 1<<11, /* __volatile__ */
93 IFF_MULTICAST = 1<<12, /* sysfs */
94 IFF_PORTSEL = 1<<13, /* sysfs */
95 IFF_AUTOMEDIA = 1<<14, /* sysfs */
96 IFF_DYNAMIC = 1<<15, /* sysfs */
97 #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS */
98 #if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
99 IFF_LOWER_UP = 1<<16, /* __volatile__ */
100 IFF_DORMANT = 1<<17, /* __volatile__ */
101 IFF_ECHO = 1<<18, /* __volatile__ */
102 #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
103 };
104 #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO != 0 || __UAPI_DEF_IF_NET_DEVICE_FLAGS != 0 */
105
106 /* for compatibility with glibc net/if.h */
107 #if __UAPI_DEF_IF_NET_DEVICE_FLAGS
108 #define IFF_UP IFF_UP
109 #define IFF_BROADCAST IFF_BROADCAST
110 #define IFF_DEBUG IFF_DEBUG
111 #define IFF_LOOPBACK IFF_LOOPBACK
112 #define IFF_POINTOPOINT IFF_POINTOPOINT
113 #define IFF_NOTRAILERS IFF_NOTRAILERS
114 #define IFF_RUNNING IFF_RUNNING
115 #define IFF_NOARP IFF_NOARP
116 #define IFF_PROMISC IFF_PROMISC
117 #define IFF_ALLMULTI IFF_ALLMULTI
118 #define IFF_MASTER IFF_MASTER
119 #define IFF_SLAVE IFF_SLAVE
120 #define IFF_MULTICAST IFF_MULTICAST
121 #define IFF_PORTSEL IFF_PORTSEL
122 #define IFF_AUTOMEDIA IFF_AUTOMEDIA
123 #define IFF_DYNAMIC IFF_DYNAMIC
124 #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS */
125
126 #if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
127 #define IFF_LOWER_UP IFF_LOWER_UP
128 #define IFF_DORMANT IFF_DORMANT
129 #define IFF_ECHO IFF_ECHO
130 #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
54131
55132 #define IFF_VOLATILE (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST|IFF_ECHO|\
56133 IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT)
57
58 /* Private (from user) interface flags (netdevice->priv_flags). */
59 #define IFF_802_1Q_VLAN 0x1 /* 802.1Q VLAN device. */
60 #define IFF_EBRIDGE 0x2 /* Ethernet bridging device. */
61 #define IFF_SLAVE_INACTIVE 0x4 /* bonding slave not the curr. active */
62 #define IFF_MASTER_8023AD 0x8 /* bonding master, 802.3ad. */
63 #define IFF_MASTER_ALB 0x10 /* bonding master, balance-alb. */
64 #define IFF_BONDING 0x20 /* bonding master or slave */
65 #define IFF_SLAVE_NEEDARP 0x40 /* need ARPs for validation */
66 #define IFF_ISATAP 0x80 /* ISATAP interface (RFC4214) */
67 #define IFF_MASTER_ARPMON 0x100 /* bonding master, ARP mon in use */
68 #define IFF_WAN_HDLC 0x200 /* WAN HDLC device */
69 #define IFF_XMIT_DST_RELEASE 0x400 /* dev_hard_start_xmit() is allowed to
70 * release skb->dst
71 */
72 #define IFF_DONT_BRIDGE 0x800 /* disallow bridging this ether dev */
73 #define IFF_DISABLE_NETPOLL 0x1000 /* disable netpoll at run-time */
74 #define IFF_MACVLAN_PORT 0x2000 /* device used as macvlan port */
75 #define IFF_BRIDGE_PORT 0x4000 /* device used as bridge port */
76 #define IFF_OVS_DATAPATH 0x8000 /* device used as Open vSwitch
77 * datapath port */
78 #define IFF_TX_SKB_SHARING 0x10000 /* The interface supports sharing
79 * skbs on transmit */
80 #define IFF_UNICAST_FLT 0x20000 /* Supports unicast filtering */
81 #define IFF_TEAM_PORT 0x40000 /* device used as team port */
82 #define IFF_SUPP_NOFCS 0x80000 /* device supports sending custom FCS */
83 #define IFF_LIVE_ADDR_CHANGE 0x100000 /* device supports hardware address
84 * change when it's running */
85
86134
87135 #define IF_GET_IFACE 0x0001 /* for querying only */
88136 #define IF_GET_PROTO 0x0002
138186 * being very small might be worth keeping for clean configuration.
139187 */
140188
189 /* for compatibility with glibc net/if.h */
190 #if __UAPI_DEF_IF_IFMAP
141191 struct ifmap {
142192 unsigned long mem_start;
143193 unsigned long mem_end;
147197 unsigned char port;
148198 /* 3 bytes spare */
149199 };
200 #endif /* __UAPI_DEF_IF_IFMAP */
150201
151202 struct if_settings {
152203 unsigned int type; /* Type of physical device or protocol */
172223 * remainder may be interface specific.
173224 */
174225
226 /* for compatibility with glibc net/if.h */
227 #if __UAPI_DEF_IF_IFREQ
175228 struct ifreq {
176229 #define IFHWADDRLEN 6
177230 union
195248 struct if_settings ifru_settings;
196249 } ifr_ifru;
197250 };
251 #endif /* __UAPI_DEF_IF_IFREQ */
198252
199253 #define ifr_name ifr_ifrn.ifrn_name /* interface name */
200254 #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
221275 * must know all networks accessible).
222276 */
223277
278 /* for compatibility with glibc net/if.h */
279 #if __UAPI_DEF_IF_IFCONF
224280 struct ifconf {
225281 int ifc_len; /* size of buffer */
226282 union {
228284 struct ifreq *ifcu_req;
229285 } ifc_ifcu;
230286 };
287 #endif /* __UAPI_DEF_IF_IFCONF */
288
231289 #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
232290 #define ifc_req ifc_ifcu.ifcu_req /* array of structures */
233291
0 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
01 #ifndef __LINUX_IF_ADDR_H
12 #define __LINUX_IF_ADDR_H
23
1718 * It makes no difference for normally configured broadcast interfaces,
1819 * but for point-to-point IFA_ADDRESS is DESTINATION address,
1920 * local address is supplied in IFA_LOCAL attribute.
21 *
22 * IFA_FLAGS is a u32 attribute that extends the u8 field ifa_flags.
23 * If present, the value from struct ifaddrmsg will be ignored.
2024 */
2125 enum {
2226 IFA_UNSPEC,
2731 IFA_ANYCAST,
2832 IFA_CACHEINFO,
2933 IFA_MULTICAST,
34 IFA_FLAGS,
35 IFA_RT_PRIORITY, /* u32, priority/metric for prefix route */
3036 __IFA_MAX,
3137 };
3238
4349 #define IFA_F_DEPRECATED 0x20
4450 #define IFA_F_TENTATIVE 0x40
4551 #define IFA_F_PERMANENT 0x80
52 #define IFA_F_MANAGETEMPADDR 0x100
53 #define IFA_F_NOPREFIXROUTE 0x200
54 #define IFA_F_MCAUTOJOIN 0x400
55 #define IFA_F_STABLE_PRIVACY 0x800
4656
4757 struct ifa_cacheinfo {
4858 __u32 ifa_prefered;
5262 };
5363
5464 /* backwards compatibility for userspace */
55 #define IFA_RTA(r) ((struct rtattr*)(void*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
65 #define IFA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
5666 #define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
5767
5868 #endif
0 /* SPDX-License-Identifier: GPL-1.0+ WITH Linux-syscall-note */
01 /*
12 * Bond several ethernet interfaces into a Cisco, running 'Etherchannel'.
23 *
9091 #define BOND_XMIT_POLICY_LAYER2 0 /* layer 2 (MAC only), default */
9192 #define BOND_XMIT_POLICY_LAYER34 1 /* layer 3+4 (IP ^ (TCP || UDP)) */
9293 #define BOND_XMIT_POLICY_LAYER23 2 /* layer 2+3 (IP ^ MAC) */
94 #define BOND_XMIT_POLICY_ENCAP23 3 /* encapsulated layer 2+3 */
95 #define BOND_XMIT_POLICY_ENCAP34 4 /* encapsulated layer 3+4 */
9396
9497 typedef struct ifbond {
9598 __s32 bond_mode;
0 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
01 /*
12 * Linux ethernet bridge
23 *
1314 #define _LINUX_IF_BRIDGE_H
1415
1516 #include <linux/types.h>
17 #include <linux/if_ether.h>
1618
1719 #define SYSFS_BRIDGE_ATTR "bridge"
1820 #define SYSFS_BRIDGE_FDB "brforward"
8789 };
8890
8991 struct __fdb_entry {
90 __u8 mac_addr[6];
92 __u8 mac_addr[ETH_ALEN];
9193 __u8 port_no;
9294 __u8 is_local;
9395 __u32 ageing_timer_value;
9698 __u16 unused;
9799 };
98100
99
100 #endif
101 /* Bridge Flags */
102 #define BRIDGE_FLAGS_MASTER 1 /* Bridge command to/from master */
103 #define BRIDGE_FLAGS_SELF 2 /* Bridge command to/from lowerdev */
104
105 #define BRIDGE_MODE_VEB 0 /* Default loopback mode */
106 #define BRIDGE_MODE_VEPA 1 /* 802.1Qbg defined VEPA mode */
107 #define BRIDGE_MODE_UNDEF 0xFFFF /* mode undefined */
108
109 /* Bridge management nested attributes
110 * [IFLA_AF_SPEC] = {
111 * [IFLA_BRIDGE_FLAGS]
112 * [IFLA_BRIDGE_MODE]
113 * [IFLA_BRIDGE_VLAN_INFO]
114 * }
115 */
116 enum {
117 IFLA_BRIDGE_FLAGS,
118 IFLA_BRIDGE_MODE,
119 IFLA_BRIDGE_VLAN_INFO,
120 IFLA_BRIDGE_VLAN_TUNNEL_INFO,
121 __IFLA_BRIDGE_MAX,
122 };
123 #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
124
125 #define BRIDGE_VLAN_INFO_MASTER (1<<0) /* Operate on Bridge device as well */
126 #define BRIDGE_VLAN_INFO_PVID (1<<1) /* VLAN is PVID, ingress untagged */
127 #define BRIDGE_VLAN_INFO_UNTAGGED (1<<2) /* VLAN egresses untagged */
128 #define BRIDGE_VLAN_INFO_RANGE_BEGIN (1<<3) /* VLAN is start of vlan range */
129 #define BRIDGE_VLAN_INFO_RANGE_END (1<<4) /* VLAN is end of vlan range */
130 #define BRIDGE_VLAN_INFO_BRENTRY (1<<5) /* Global bridge VLAN entry */
131
132 struct bridge_vlan_info {
133 __u16 flags;
134 __u16 vid;
135 };
136
137 enum {
138 IFLA_BRIDGE_VLAN_TUNNEL_UNSPEC,
139 IFLA_BRIDGE_VLAN_TUNNEL_ID,
140 IFLA_BRIDGE_VLAN_TUNNEL_VID,
141 IFLA_BRIDGE_VLAN_TUNNEL_FLAGS,
142 __IFLA_BRIDGE_VLAN_TUNNEL_MAX,
143 };
144
145 #define IFLA_BRIDGE_VLAN_TUNNEL_MAX (__IFLA_BRIDGE_VLAN_TUNNEL_MAX - 1)
146
147 struct bridge_vlan_xstats {
148 __u64 rx_bytes;
149 __u64 rx_packets;
150 __u64 tx_bytes;
151 __u64 tx_packets;
152 __u16 vid;
153 __u16 flags;
154 __u32 pad2;
155 };
156
157 /* Bridge multicast database attributes
158 * [MDBA_MDB] = {
159 * [MDBA_MDB_ENTRY] = {
160 * [MDBA_MDB_ENTRY_INFO] {
161 * struct br_mdb_entry
162 * [MDBA_MDB_EATTR attributes]
163 * }
164 * }
165 * }
166 * [MDBA_ROUTER] = {
167 * [MDBA_ROUTER_PORT] = {
168 * u32 ifindex
169 * [MDBA_ROUTER_PATTR attributes]
170 * }
171 * }
172 */
173 enum {
174 MDBA_UNSPEC,
175 MDBA_MDB,
176 MDBA_ROUTER,
177 __MDBA_MAX,
178 };
179 #define MDBA_MAX (__MDBA_MAX - 1)
180
181 enum {
182 MDBA_MDB_UNSPEC,
183 MDBA_MDB_ENTRY,
184 __MDBA_MDB_MAX,
185 };
186 #define MDBA_MDB_MAX (__MDBA_MDB_MAX - 1)
187
188 enum {
189 MDBA_MDB_ENTRY_UNSPEC,
190 MDBA_MDB_ENTRY_INFO,
191 __MDBA_MDB_ENTRY_MAX,
192 };
193 #define MDBA_MDB_ENTRY_MAX (__MDBA_MDB_ENTRY_MAX - 1)
194
195 /* per mdb entry additional attributes */
196 enum {
197 MDBA_MDB_EATTR_UNSPEC,
198 MDBA_MDB_EATTR_TIMER,
199 __MDBA_MDB_EATTR_MAX
200 };
201 #define MDBA_MDB_EATTR_MAX (__MDBA_MDB_EATTR_MAX - 1)
202
203 /* multicast router types */
204 enum {
205 MDB_RTR_TYPE_DISABLED,
206 MDB_RTR_TYPE_TEMP_QUERY,
207 MDB_RTR_TYPE_PERM,
208 MDB_RTR_TYPE_TEMP
209 };
210
211 enum {
212 MDBA_ROUTER_UNSPEC,
213 MDBA_ROUTER_PORT,
214 __MDBA_ROUTER_MAX,
215 };
216 #define MDBA_ROUTER_MAX (__MDBA_ROUTER_MAX - 1)
217
218 /* router port attributes */
219 enum {
220 MDBA_ROUTER_PATTR_UNSPEC,
221 MDBA_ROUTER_PATTR_TIMER,
222 MDBA_ROUTER_PATTR_TYPE,
223 __MDBA_ROUTER_PATTR_MAX
224 };
225 #define MDBA_ROUTER_PATTR_MAX (__MDBA_ROUTER_PATTR_MAX - 1)
226
227 struct br_port_msg {
228 __u8 family;
229 __u32 ifindex;
230 };
231
232 enum {
233 MDBA_SET_ENTRY_UNSPEC,
234 MDBA_SET_ENTRY,
235 __MDBA_SET_ENTRY_MAX,
236 };
237 #define MDBA_SET_ENTRY_MAX (__MDBA_SET_ENTRY_MAX - 1)
238
239 /* Embedded inside LINK_XSTATS_TYPE_BRIDGE */
240 enum {
241 BRIDGE_XSTATS_UNSPEC,
242 BRIDGE_XSTATS_VLAN,
243 BRIDGE_XSTATS_MCAST,
244 BRIDGE_XSTATS_PAD,
245 __BRIDGE_XSTATS_MAX
246 };
247 #define BRIDGE_XSTATS_MAX (__BRIDGE_XSTATS_MAX - 1)
248
249 enum {
250 BR_MCAST_DIR_RX,
251 BR_MCAST_DIR_TX,
252 BR_MCAST_DIR_SIZE
253 };
254
255 /* IGMP/MLD statistics */
256 struct br_mcast_stats {
257 __u64 igmp_v1queries[BR_MCAST_DIR_SIZE];
258 __u64 igmp_v2queries[BR_MCAST_DIR_SIZE];
259 __u64 igmp_v3queries[BR_MCAST_DIR_SIZE];
260 __u64 igmp_leaves[BR_MCAST_DIR_SIZE];
261 __u64 igmp_v1reports[BR_MCAST_DIR_SIZE];
262 __u64 igmp_v2reports[BR_MCAST_DIR_SIZE];
263 __u64 igmp_v3reports[BR_MCAST_DIR_SIZE];
264 __u64 igmp_parse_errors;
265
266 __u64 mld_v1queries[BR_MCAST_DIR_SIZE];
267 __u64 mld_v2queries[BR_MCAST_DIR_SIZE];
268 __u64 mld_leaves[BR_MCAST_DIR_SIZE];
269 __u64 mld_v1reports[BR_MCAST_DIR_SIZE];
270 __u64 mld_v2reports[BR_MCAST_DIR_SIZE];
271 __u64 mld_parse_errors;
272
273 __u64 mcast_bytes[BR_MCAST_DIR_SIZE];
274 __u64 mcast_packets[BR_MCAST_DIR_SIZE];
275 };
276 #endif /* _LINUX_IF_BRIDGE_H */
0 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
01 /*
12 * INET An implementation of the TCP/IP protocol suite for the LINUX
23 * operating system. INET is implemented using the BSD Socket
2829 */
2930
3031 #define ETH_ALEN 6 /* Octets in one ethernet addr */
32 #define ETH_TLEN 2 /* Octets in ethernet type field */
3133 #define ETH_HLEN 14 /* Total octets in header. */
3234 #define ETH_ZLEN 60 /* Min. octets in frame sans FCS */
3335 #define ETH_DATA_LEN 1500 /* Max. octets in payload */
3436 #define ETH_FRAME_LEN 1514 /* Max. octets in frame sans FCS */
3537 #define ETH_FCS_LEN 4 /* Octets in the FCS */
38
39 #define ETH_MIN_MTU 68 /* Min IPv4 MTU per RFC791 */
40 #define ETH_MAX_MTU 0xFFFFU /* 65535, same as IP_MAX_MTU */
3641
3742 /*
3843 * These are the defined Ethernet Protocol ID's.
4146 #define ETH_P_LOOP 0x0060 /* Ethernet Loopback packet */
4247 #define ETH_P_PUP 0x0200 /* Xerox PUP packet */
4348 #define ETH_P_PUPAT 0x0201 /* Xerox PUP Addr Trans packet */
49 #define ETH_P_TSN 0x22F0 /* TSN (IEEE 1722) packet */
50 #define ETH_P_ERSPAN2 0x22EB /* ERSPAN version 2 (type III) */
4451 #define ETH_P_IP 0x0800 /* Internet Protocol packet */
4552 #define ETH_P_X25 0x0805 /* CCITT X.25 */
4653 #define ETH_P_ARP 0x0806 /* Address Resolution packet */
4754 #define ETH_P_BPQ 0x08FF /* G8BPQ AX.25 Ethernet Packet [ NOT AN OFFICIALLY REGISTERED ID ] */
4855 #define ETH_P_IEEEPUP 0x0a00 /* Xerox IEEE802.3 PUP packet */
4956 #define ETH_P_IEEEPUPAT 0x0a01 /* Xerox IEEE802.3 PUP Addr Trans packet */
57 #define ETH_P_BATMAN 0x4305 /* B.A.T.M.A.N.-Advanced packet [ NOT AN OFFICIALLY REGISTERED ID ] */
5058 #define ETH_P_DEC 0x6000 /* DEC Assigned proto */
5159 #define ETH_P_DNA_DL 0x6001 /* DEC DNA Dump/Load */
5260 #define ETH_P_DNA_RC 0x6002 /* DEC DNA Remote Console */
6068 #define ETH_P_ATALK 0x809B /* Appletalk DDP */
6169 #define ETH_P_AARP 0x80F3 /* Appletalk AARP */
6270 #define ETH_P_8021Q 0x8100 /* 802.1Q VLAN Extended Header */
71 #define ETH_P_ERSPAN 0x88BE /* ERSPAN type II */
6372 #define ETH_P_IPX 0x8137 /* IPX over DIX */
6473 #define ETH_P_IPV6 0x86DD /* IPv6 over bluebook */
6574 #define ETH_P_PAUSE 0x8808 /* IEEE Pause frames. See 802.3 31B */
6675 #define ETH_P_SLOW 0x8809 /* Slow Protocol. See 802.3ad 43B */
6776 #define ETH_P_WCCP 0x883E /* Web-cache coordination protocol
6877 * defined in draft-wilson-wrec-wccp-v2-00.txt */
69 #define ETH_P_PPP_DISC 0x8863 /* PPPoE discovery messages */
70 #define ETH_P_PPP_SES 0x8864 /* PPPoE session messages */
7178 #define ETH_P_MPLS_UC 0x8847 /* MPLS Unicast traffic */
7279 #define ETH_P_MPLS_MC 0x8848 /* MPLS Multicast traffic */
7380 #define ETH_P_ATMMPOA 0x884c /* MultiProtocol Over ATM */
81 #define ETH_P_PPP_DISC 0x8863 /* PPPoE discovery messages */
82 #define ETH_P_PPP_SES 0x8864 /* PPPoE session messages */
7483 #define ETH_P_LINK_CTL 0x886c /* HPNA, wlan link local tunnel */
7584 #define ETH_P_ATMFATE 0x8884 /* Frame-based ATM Transport
7685 * over Ethernet
7988 #define ETH_P_AOE 0x88A2 /* ATA over Ethernet */
8089 #define ETH_P_8021AD 0x88A8 /* 802.1ad Service VLAN */
8190 #define ETH_P_802_EX1 0x88B5 /* 802.1 Local Experimental 1. */
91 #define ETH_P_PREAUTH 0x88C7 /* 802.11 Preauthentication */
8292 #define ETH_P_TIPC 0x88CA /* TIPC */
93 #define ETH_P_MACSEC 0x88E5 /* 802.1ae MACsec */
8394 #define ETH_P_8021AH 0x88E7 /* 802.1ah Backbone Service Tag */
95 #define ETH_P_MVRP 0x88F5 /* 802.1Q MVRP */
8496 #define ETH_P_1588 0x88F7 /* IEEE 1588 Timesync */
97 #define ETH_P_NCSI 0x88F8 /* NCSI protocol */
98 #define ETH_P_PRP 0x88FB /* IEC 62439-3 PRP/HSRv0 */
8599 #define ETH_P_FCOE 0x8906 /* Fibre Channel over Ethernet */
100 #define ETH_P_IBOE 0x8915 /* Infiniband over Ethernet */
86101 #define ETH_P_TDLS 0x890D /* TDLS */
87102 #define ETH_P_FIP 0x8914 /* FCoE Initialization Protocol */
103 #define ETH_P_80221 0x8917 /* IEEE 802.21 Media Independent Handover Protocol */
104 #define ETH_P_HSR 0x892F /* IEC 62439-3 HSRv1 */
105 #define ETH_P_NSH 0x894F /* Network Service Header */
106 #define ETH_P_LOOPBACK 0x9000 /* Ethernet loopback packet, per IEEE 802.3 */
88107 #define ETH_P_QINQ1 0x9100 /* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */
89108 #define ETH_P_QINQ2 0x9200 /* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */
90109 #define ETH_P_QINQ3 0x9300 /* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */
91110 #define ETH_P_EDSA 0xDADA /* Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] */
111 #define ETH_P_IFE 0xED3E /* ForCES inter-FE LFB type */
92112 #define ETH_P_AF_IUCV 0xFBFB /* IBM af_iucv [ NOT AN OFFICIALLY REGISTERED ID ] */
113
114 #define ETH_P_802_3_MIN 0x0600 /* If the value in the ethernet type is less than this value
115 * then the frame is Ethernet II. Else it is 802.3 */
93116
94117 /*
95118 * Non DIX types. Won't clash for 1500 types.
119142 #define ETH_P_PHONET 0x00F5 /* Nokia Phonet frames */
120143 #define ETH_P_IEEE802154 0x00F6 /* IEEE802.15.4 frame */
121144 #define ETH_P_CAIF 0x00F7 /* ST-Ericsson CAIF protocol */
145 #define ETH_P_XDSA 0x00F8 /* Multiplexed DSA protocol */
146 #define ETH_P_MAP 0x00F9 /* Qualcomm multiplexing and
147 * aggregation protocol
148 */
122149
123150 /*
124151 * This is an Ethernet frame header.
125152 */
126153
154 /* allow libcs like musl to deactivate this, glibc does not implement this. */
155 #ifndef __UAPI_DEF_ETHHDR
156 #define __UAPI_DEF_ETHHDR 1
157 #endif
158
159 #if __UAPI_DEF_ETHHDR
127160 struct ethhdr {
128161 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
129162 unsigned char h_source[ETH_ALEN]; /* source ether addr */
130163 __be16 h_proto; /* packet type ID field */
131164 } __attribute__((packed));
165 #endif
132166
133167
134 #endif /* _LINUX_IF_ETHER_H */
168 #endif /* _LINUX_IF_ETHER_H */
0 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
01 #ifndef _LINUX_IF_LINK_H
12 #define _LINUX_IF_LINK_H
23
3435 /* for cslip etc */
3536 __u32 rx_compressed;
3637 __u32 tx_compressed;
38
39 __u32 rx_nohandler; /* dropped, no handler found */
3740 };
3841
3942 /* The main device statistics structure */
6770 /* for cslip etc */
6871 __u64 rx_compressed;
6972 __u64 tx_compressed;
73
74 __u64 rx_nohandler; /* dropped, no handler found */
7075 };
7176
7277 /* The struct should be in sync with struct ifmap */
148153 IFLA_LINK_NETNSID,
149154 IFLA_PHYS_PORT_NAME,
150155 IFLA_PROTO_DOWN,
156 IFLA_GSO_MAX_SEGS,
157 IFLA_GSO_MAX_SIZE,
158 IFLA_PAD,
159 IFLA_XDP,
160 IFLA_EVENT,
161 IFLA_NEW_NETNSID,
162 IFLA_IF_NETNSID,
163 IFLA_CARRIER_UP_COUNT,
164 IFLA_CARRIER_DOWN_COUNT,
165 IFLA_NEW_IFINDEX,
166 IFLA_MIN_MTU,
167 IFLA_MAX_MTU,
151168 __IFLA_MAX
152169 };
153170
155172 #define IFLA_MAX (__IFLA_MAX - 1)
156173
157174 /* backwards compatibility for userspace */
158 #define IFLA_RTA(r) ((struct rtattr*)(void*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
175 #define IFLA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
159176 #define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
160177
161178 enum {
215232 IN6_ADDR_GEN_MODE_EUI64,
216233 IN6_ADDR_GEN_MODE_NONE,
217234 IN6_ADDR_GEN_MODE_STABLE_PRIVACY,
235 IN6_ADDR_GEN_MODE_RANDOM,
218236 };
219237
220238 /* Bridge section */
260278 IFLA_BR_NF_CALL_IP6TABLES,
261279 IFLA_BR_NF_CALL_ARPTABLES,
262280 IFLA_BR_VLAN_DEFAULT_PVID,
281 IFLA_BR_PAD,
282 IFLA_BR_VLAN_STATS_ENABLED,
283 IFLA_BR_MCAST_STATS_ENABLED,
284 IFLA_BR_MCAST_IGMP_VERSION,
285 IFLA_BR_MCAST_MLD_VERSION,
263286 __IFLA_BR_MAX,
264287 };
265288
302325 IFLA_BRPORT_HOLD_TIMER,
303326 IFLA_BRPORT_FLUSH,
304327 IFLA_BRPORT_MULTICAST_ROUTER,
328 IFLA_BRPORT_PAD,
329 IFLA_BRPORT_MCAST_FLOOD,
330 IFLA_BRPORT_MCAST_TO_UCAST,
331 IFLA_BRPORT_VLAN_TUNNEL,
332 IFLA_BRPORT_BCAST_FLOOD,
333 IFLA_BRPORT_GROUP_FWD_MASK,
334 IFLA_BRPORT_NEIGH_SUPPRESS,
335 IFLA_BRPORT_ISOLATED,
336 IFLA_BRPORT_BACKUP_PORT,
305337 __IFLA_BRPORT_MAX
306338 };
307339 #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
397429
398430 #define IFLA_VRF_MAX (__IFLA_VRF_MAX - 1)
399431
432 enum {
433 IFLA_VRF_PORT_UNSPEC,
434 IFLA_VRF_PORT_TABLE,
435 __IFLA_VRF_PORT_MAX
436 };
437
438 #define IFLA_VRF_PORT_MAX (__IFLA_VRF_PORT_MAX - 1)
439
440 /* MACSEC section */
441 enum {
442 IFLA_MACSEC_UNSPEC,
443 IFLA_MACSEC_SCI,
444 IFLA_MACSEC_PORT,
445 IFLA_MACSEC_ICV_LEN,
446 IFLA_MACSEC_CIPHER_SUITE,
447 IFLA_MACSEC_WINDOW,
448 IFLA_MACSEC_ENCODING_SA,
449 IFLA_MACSEC_ENCRYPT,
450 IFLA_MACSEC_PROTECT,
451 IFLA_MACSEC_INC_SCI,
452 IFLA_MACSEC_ES,
453 IFLA_MACSEC_SCB,
454 IFLA_MACSEC_REPLAY_PROTECT,
455 IFLA_MACSEC_VALIDATION,
456 IFLA_MACSEC_PAD,
457 __IFLA_MACSEC_MAX,
458 };
459
460 #define IFLA_MACSEC_MAX (__IFLA_MACSEC_MAX - 1)
461
462 /* XFRM section */
463 enum {
464 IFLA_XFRM_UNSPEC,
465 IFLA_XFRM_LINK,
466 IFLA_XFRM_IF_ID,
467 __IFLA_XFRM_MAX
468 };
469
470 #define IFLA_XFRM_MAX (__IFLA_XFRM_MAX - 1)
471
472 enum macsec_validation_type {
473 MACSEC_VALIDATE_DISABLED = 0,
474 MACSEC_VALIDATE_CHECK = 1,
475 MACSEC_VALIDATE_STRICT = 2,
476 __MACSEC_VALIDATE_END,
477 MACSEC_VALIDATE_MAX = __MACSEC_VALIDATE_END - 1,
478 };
479
400480 /* IPVLAN section */
401481 enum {
402482 IFLA_IPVLAN_UNSPEC,
403483 IFLA_IPVLAN_MODE,
484 IFLA_IPVLAN_FLAGS,
404485 __IFLA_IPVLAN_MAX
405486 };
406487
409490 enum ipvlan_mode {
410491 IPVLAN_MODE_L2 = 0,
411492 IPVLAN_MODE_L3,
493 IPVLAN_MODE_L3S,
412494 IPVLAN_MODE_MAX
413495 };
496
497 #define IPVLAN_F_PRIVATE 0x01
498 #define IPVLAN_F_VEPA 0x02
414499
415500 /* VXLAN section */
416501 enum {
440525 IFLA_VXLAN_GBP,
441526 IFLA_VXLAN_REMCSUM_NOPARTIAL,
442527 IFLA_VXLAN_COLLECT_METADATA,
528 IFLA_VXLAN_LABEL,
529 IFLA_VXLAN_GPE,
530 IFLA_VXLAN_TTL_INHERIT,
443531 __IFLA_VXLAN_MAX
444532 };
445533 #define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1)
459547 IFLA_GENEVE_PORT, /* destination port */
460548 IFLA_GENEVE_COLLECT_METADATA,
461549 IFLA_GENEVE_REMOTE6,
550 IFLA_GENEVE_UDP_CSUM,
551 IFLA_GENEVE_UDP_ZERO_CSUM6_TX,
552 IFLA_GENEVE_UDP_ZERO_CSUM6_RX,
553 IFLA_GENEVE_LABEL,
462554 __IFLA_GENEVE_MAX
463555 };
464556 #define IFLA_GENEVE_MAX (__IFLA_GENEVE_MAX - 1)
557
558 /* PPP section */
559 enum {
560 IFLA_PPP_UNSPEC,
561 IFLA_PPP_DEV_FD,
562 __IFLA_PPP_MAX
563 };
564 #define IFLA_PPP_MAX (__IFLA_PPP_MAX - 1)
565
566 /* GTP section */
567
568 enum ifla_gtp_role {
569 GTP_ROLE_GGSN = 0,
570 GTP_ROLE_SGSN,
571 };
572
573 enum {
574 IFLA_GTP_UNSPEC,
575 IFLA_GTP_FD0,
576 IFLA_GTP_FD1,
577 IFLA_GTP_PDP_HASHSIZE,
578 IFLA_GTP_ROLE,
579 __IFLA_GTP_MAX,
580 };
581 #define IFLA_GTP_MAX (__IFLA_GTP_MAX - 1)
465582
466583 /* Bonding section */
467584
539656 enum {
540657 IFLA_VF_UNSPEC,
541658 IFLA_VF_MAC, /* Hardware queue specific attributes */
542 IFLA_VF_VLAN,
659 IFLA_VF_VLAN, /* VLAN ID and QoS */
543660 IFLA_VF_TX_RATE, /* Max TX Bandwidth Allocation */
544661 IFLA_VF_SPOOFCHK, /* Spoof Checking on/off switch */
545662 IFLA_VF_LINK_STATE, /* link state enable/disable/auto switch */
549666 */
550667 IFLA_VF_STATS, /* network device statistics */
551668 IFLA_VF_TRUST, /* Trust VF */
669 IFLA_VF_IB_NODE_GUID, /* VF Infiniband node GUID */
670 IFLA_VF_IB_PORT_GUID, /* VF Infiniband port GUID */
671 IFLA_VF_VLAN_LIST, /* nested list of vlans, option for QinQ */
552672 __IFLA_VF_MAX,
553673 };
554674
565685 __u32 qos;
566686 };
567687
688 enum {
689 IFLA_VF_VLAN_INFO_UNSPEC,
690 IFLA_VF_VLAN_INFO, /* VLAN ID, QoS and VLAN protocol */
691 __IFLA_VF_VLAN_INFO_MAX,
692 };
693
694 #define IFLA_VF_VLAN_INFO_MAX (__IFLA_VF_VLAN_INFO_MAX - 1)
695 #define MAX_VLAN_LIST_LEN 1
696
697 struct ifla_vf_vlan_info {
698 __u32 vf;
699 __u32 vlan; /* 0 - 4095, 0 disables VLAN filter */
700 __u32 qos;
701 __be16 vlan_proto; /* VLAN protocol either 802.1Q or 802.1ad */
702 };
703
568704 struct ifla_vf_tx_rate {
569705 __u32 vf;
570706 __u32 rate; /* Max TX bandwidth in Mbps, 0 disables throttling */
579715 struct ifla_vf_spoofchk {
580716 __u32 vf;
581717 __u32 setting;
718 };
719
720 struct ifla_vf_guid {
721 __u32 vf;
722 __u64 guid;
582723 };
583724
584725 enum {
605746 IFLA_VF_STATS_TX_BYTES,
606747 IFLA_VF_STATS_BROADCAST,
607748 IFLA_VF_STATS_MULTICAST,
749 IFLA_VF_STATS_PAD,
750 IFLA_VF_STATS_RX_DROPPED,
751 IFLA_VF_STATS_TX_DROPPED,
608752 __IFLA_VF_STATS_MAX,
609753 };
610754
715859 IFLA_HSR_MULTICAST_SPEC, /* Last byte of supervision addr */
716860 IFLA_HSR_SUPERVISION_ADDR, /* Supervision frame multicast addr */
717861 IFLA_HSR_SEQ_NR,
862 IFLA_HSR_VERSION, /* HSR version */
718863 __IFLA_HSR_MAX,
719864 };
720865
721866 #define IFLA_HSR_MAX (__IFLA_HSR_MAX - 1)
722867
868 /* STATS section */
869
870 struct if_stats_msg {
871 __u8 family;
872 __u8 pad1;
873 __u16 pad2;
874 __u32 ifindex;
875 __u32 filter_mask;
876 };
877
878 /* A stats attribute can be netdev specific or a global stat.
879 * For netdev stats, lets use the prefix IFLA_STATS_LINK_*
880 */
881 enum {
882 IFLA_STATS_UNSPEC, /* also used as 64bit pad attribute */
883 IFLA_STATS_LINK_64,
884 IFLA_STATS_LINK_XSTATS,
885 IFLA_STATS_LINK_XSTATS_SLAVE,
886 IFLA_STATS_LINK_OFFLOAD_XSTATS,
887 IFLA_STATS_AF_SPEC,
888 __IFLA_STATS_MAX,
889 };
890
891 #define IFLA_STATS_MAX (__IFLA_STATS_MAX - 1)
892
893 #define IFLA_STATS_FILTER_BIT(ATTR) (1 << (ATTR - 1))
894
895 /* These are embedded into IFLA_STATS_LINK_XSTATS:
896 * [IFLA_STATS_LINK_XSTATS]
897 * -> [LINK_XSTATS_TYPE_xxx]
898 * -> [rtnl link type specific attributes]
899 */
900 enum {
901 LINK_XSTATS_TYPE_UNSPEC,
902 LINK_XSTATS_TYPE_BRIDGE,
903 __LINK_XSTATS_TYPE_MAX
904 };
905 #define LINK_XSTATS_TYPE_MAX (__LINK_XSTATS_TYPE_MAX - 1)
906
907 /* These are stats embedded into IFLA_STATS_LINK_OFFLOAD_XSTATS */
908 enum {
909 IFLA_OFFLOAD_XSTATS_UNSPEC,
910 IFLA_OFFLOAD_XSTATS_CPU_HIT, /* struct rtnl_link_stats64 */
911 __IFLA_OFFLOAD_XSTATS_MAX
912 };
913 #define IFLA_OFFLOAD_XSTATS_MAX (__IFLA_OFFLOAD_XSTATS_MAX - 1)
914
915 /* XDP section */
916
917 #define XDP_FLAGS_UPDATE_IF_NOEXIST (1U << 0)
918 #define XDP_FLAGS_SKB_MODE (1U << 1)
919 #define XDP_FLAGS_DRV_MODE (1U << 2)
920 #define XDP_FLAGS_HW_MODE (1U << 3)
921 #define XDP_FLAGS_MODES (XDP_FLAGS_SKB_MODE | \
922 XDP_FLAGS_DRV_MODE | \
923 XDP_FLAGS_HW_MODE)
924 #define XDP_FLAGS_MASK (XDP_FLAGS_UPDATE_IF_NOEXIST | \
925 XDP_FLAGS_MODES)
926
927 /* These are stored into IFLA_XDP_ATTACHED on dump. */
928 enum {
929 XDP_ATTACHED_NONE = 0,
930 XDP_ATTACHED_DRV,
931 XDP_ATTACHED_SKB,
932 XDP_ATTACHED_HW,
933 XDP_ATTACHED_MULTI,
934 };
935
936 enum {
937 IFLA_XDP_UNSPEC,
938 IFLA_XDP_FD,
939 IFLA_XDP_ATTACHED,
940 IFLA_XDP_FLAGS,
941 IFLA_XDP_PROG_ID,
942 IFLA_XDP_DRV_PROG_ID,
943 IFLA_XDP_SKB_PROG_ID,
944 IFLA_XDP_HW_PROG_ID,
945 __IFLA_XDP_MAX,
946 };
947
948 #define IFLA_XDP_MAX (__IFLA_XDP_MAX - 1)
949
950 enum {
951 IFLA_EVENT_NONE,
952 IFLA_EVENT_REBOOT, /* internal reset / reboot */
953 IFLA_EVENT_FEATURES, /* change in offload features */
954 IFLA_EVENT_BONDING_FAILOVER, /* change in active slave */
955 IFLA_EVENT_NOTIFY_PEERS, /* re-sent grat. arp/ndisc */
956 IFLA_EVENT_IGMP_RESEND, /* re-sent IGMP JOIN */
957 IFLA_EVENT_BONDING_OPTIONS, /* change in bonding options */
958 };
959
960 /* tun section */
961
962 enum {
963 IFLA_TUN_UNSPEC,
964 IFLA_TUN_OWNER,
965 IFLA_TUN_GROUP,
966 IFLA_TUN_TYPE,
967 IFLA_TUN_PI,
968 IFLA_TUN_VNET_HDR,
969 IFLA_TUN_PERSIST,
970 IFLA_TUN_MULTI_QUEUE,
971 IFLA_TUN_NUM_QUEUES,
972 IFLA_TUN_NUM_DISABLED_QUEUES,
973 __IFLA_TUN_MAX,
974 };
975
976 #define IFLA_TUN_MAX (__IFLA_TUN_MAX - 1)
977
978 /* rmnet section */
979
980 #define RMNET_FLAGS_INGRESS_DEAGGREGATION (1U << 0)
981 #define RMNET_FLAGS_INGRESS_MAP_COMMANDS (1U << 1)
982 #define RMNET_FLAGS_INGRESS_MAP_CKSUMV4 (1U << 2)
983 #define RMNET_FLAGS_EGRESS_MAP_CKSUMV4 (1U << 3)
984
985 enum {
986 IFLA_RMNET_UNSPEC,
987 IFLA_RMNET_MUX_ID,
988 IFLA_RMNET_FLAGS,
989 __IFLA_RMNET_MAX,
990 };
991
992 #define IFLA_RMNET_MAX (__IFLA_RMNET_MAX - 1)
993
994 struct ifla_rmnet_flags {
995 __u32 flags;
996 __u32 mask;
997 };
998
723999 #endif /* _LINUX_IF_LINK_H */
0 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
01 #ifndef __LINUX_IF_PACKET_H
12 #define __LINUX_IF_PACKET_H
23
2526 #define PACKET_MULTICAST 2 /* To group */
2627 #define PACKET_OTHERHOST 3 /* To someone else */
2728 #define PACKET_OUTGOING 4 /* Outgoing of any type */
28 /* These ones are invisible by user level */
2929 #define PACKET_LOOPBACK 5 /* MC/BRD frame looped back */
30 #define PACKET_USER 6 /* To user space */
31 #define PACKET_KERNEL 7 /* To kernel space */
32 /* Unused, PACKET_FASTROUTE and PACKET_LOOPBACK are invisible to user space */
3033 #define PACKET_FASTROUTE 6 /* Fastrouted frame */
3134
3235 /* Packet socket options */
4952 #define PACKET_TX_TIMESTAMP 16
5053 #define PACKET_TIMESTAMP 17
5154 #define PACKET_FANOUT 18
55 #define PACKET_TX_HAS_OFF 19
56 #define PACKET_QDISC_BYPASS 20
57 #define PACKET_ROLLOVER_STATS 21
58 #define PACKET_FANOUT_DATA 22
5259
5360 #define PACKET_FANOUT_HASH 0
5461 #define PACKET_FANOUT_LB 1
5562 #define PACKET_FANOUT_CPU 2
63 #define PACKET_FANOUT_ROLLOVER 3
64 #define PACKET_FANOUT_RND 4
65 #define PACKET_FANOUT_QM 5
66 #define PACKET_FANOUT_CBPF 6
67 #define PACKET_FANOUT_EBPF 7
68 #define PACKET_FANOUT_FLAG_ROLLOVER 0x1000
69 #define PACKET_FANOUT_FLAG_UNIQUEID 0x2000
5670 #define PACKET_FANOUT_FLAG_DEFRAG 0x8000
5771
5872 struct tpacket_stats {
6478 unsigned int tp_packets;
6579 unsigned int tp_drops;
6680 unsigned int tp_freeze_q_cnt;
81 };
82
83 struct tpacket_rollover_stats {
84 __aligned_u64 tp_all;
85 __aligned_u64 tp_huge;
86 __aligned_u64 tp_failed;
6787 };
6888
6989 union tpacket_stats_u {
7898 __u16 tp_mac;
7999 __u16 tp_net;
80100 __u16 tp_vlan_tci;
81 __u16 tp_padding;
101 __u16 tp_vlan_tpid;
82102 };
83103
84104 /* Rx ring - header status */
85 #define TP_STATUS_KERNEL 0x0
86 #define TP_STATUS_USER 0x1
87 #define TP_STATUS_COPY 0x2
88 #define TP_STATUS_LOSING 0x4
89 #define TP_STATUS_CSUMNOTREADY 0x8
90 #define TP_STATUS_VLAN_VALID 0x10 /* auxdata has valid tp_vlan_tci */
91 #define TP_STATUS_BLK_TMO 0x20
105 #define TP_STATUS_KERNEL 0
106 #define TP_STATUS_USER (1 << 0)
107 #define TP_STATUS_COPY (1 << 1)
108 #define TP_STATUS_LOSING (1 << 2)
109 #define TP_STATUS_CSUMNOTREADY (1 << 3)
110 #define TP_STATUS_VLAN_VALID (1 << 4) /* auxdata has valid tp_vlan_tci */
111 #define TP_STATUS_BLK_TMO (1 << 5)
112 #define TP_STATUS_VLAN_TPID_VALID (1 << 6) /* auxdata has valid tp_vlan_tpid */
113 #define TP_STATUS_CSUM_VALID (1 << 7)
92114
93115 /* Tx ring - header status */
94 #define TP_STATUS_AVAILABLE 0x0
95 #define TP_STATUS_SEND_REQUEST 0x1
96 #define TP_STATUS_SENDING 0x2
97 #define TP_STATUS_WRONG_FORMAT 0x4
116 #define TP_STATUS_AVAILABLE 0
117 #define TP_STATUS_SEND_REQUEST (1 << 0)
118 #define TP_STATUS_SENDING (1 << 1)
119 #define TP_STATUS_WRONG_FORMAT (1 << 2)
120
121 /* Rx and Tx ring - header status */
122 #define TP_STATUS_TS_SOFTWARE (1 << 29)
123 #define TP_STATUS_TS_SYS_HARDWARE (1 << 30) /* deprecated, never set */
124 #define TP_STATUS_TS_RAW_HARDWARE (1 << 31)
98125
99126 /* Rx ring - feature request bits */
100127 #define TP_FT_REQ_FILL_RXHASH 0x1
122149 __u32 tp_sec;
123150 __u32 tp_nsec;
124151 __u16 tp_vlan_tci;
125 __u16 tp_padding;
152 __u16 tp_vlan_tpid;
153 __u8 tp_padding[4];
126154 };
127155
128156 struct tpacket_hdr_variant1 {
129157 __u32 tp_rxhash;
130158 __u32 tp_vlan_tci;
159 __u16 tp_vlan_tpid;
160 __u16 tp_padding;
131161 };
132162
133163 struct tpacket3_hdr {
143173 union {
144174 struct tpacket_hdr_variant1 hv1;
145175 };
176 __u8 tp_padding[8];
146177 };
147178
148179 struct tpacket_bd_ts {
0 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
01 /*
12 * VLAN An implementation of 802.1Q VLAN tagging.
23 *
3334 VLAN_FLAG_REORDER_HDR = 0x1,
3435 VLAN_FLAG_GVRP = 0x2,
3536 VLAN_FLAG_LOOSE_BINDING = 0x4,
37 VLAN_FLAG_MVRP = 0x8,
3638 };
3739
3840 enum vlan_name_types {
5961 short vlan_qos;
6062 };
6163
62 #endif /* !(_LINUX_IF_VLAN_H_) */
64 #endif /* _LINUX_IF_VLAN_H_ */
0 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1 #ifndef _LINUX_KERNEL_H
2 #define _LINUX_KERNEL_H
3
4 #include <linux/types.h>
5
6 /*
7 * 'kernel.h' contains some often-used function prototypes etc
8 */
9 #define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
10 #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
11
12 #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
13
14 #endif /* _LINUX_KERNEL_H */
0 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1 /*
2 * Compatibility interface for userspace libc header coordination:
3 *
4 * Define compatibility macros that are used to control the inclusion or
5 * exclusion of UAPI structures and definitions in coordination with another
6 * userspace C library.
7 *
8 * This header is intended to solve the problem of UAPI definitions that
9 * conflict with userspace definitions. If a UAPI header has such conflicting
10 * definitions then the solution is as follows:
11 *
12 * * Synchronize the UAPI header and the libc headers so either one can be
13 * used and such that the ABI is preserved. If this is not possible then
14 * no simple compatibility interface exists (you need to write translating
15 * wrappers and rename things) and you can't use this interface.
16 *
17 * Then follow this process:
18 *
19 * (a) Include libc-compat.h in the UAPI header.
20 * e.g. #include <linux/libc-compat.h>
21 * This include must be as early as possible.
22 *
23 * (b) In libc-compat.h add enough code to detect that the comflicting
24 * userspace libc header has been included first.
25 *
26 * (c) If the userspace libc header has been included first define a set of
27 * guard macros of the form __UAPI_DEF_FOO and set their values to 1, else
28 * set their values to 0.
29 *
30 * (d) Back in the UAPI header with the conflicting definitions, guard the
31 * definitions with:
32 * #if __UAPI_DEF_FOO
33 * ...
34 * #endif
35 *
36 * This fixes the situation where the linux headers are included *after* the
37 * libc headers. To fix the problem with the inclusion in the other order the
38 * userspace libc headers must be fixed like this:
39 *
40 * * For all definitions that conflict with kernel definitions wrap those
41 * defines in the following:
42 * #if !__UAPI_DEF_FOO
43 * ...
44 * #endif
45 *
46 * This prevents the redefinition of a construct already defined by the kernel.
47 */
48 #ifndef _LIBC_COMPAT_H
49 #define _LIBC_COMPAT_H
50
51 /* We have included glibc headers... */
52 #if defined(__GLIBC__)
53
54 /* Coordinate with glibc net/if.h header. */
55 #if defined(_NET_IF_H) && defined(__USE_MISC)
56
57 /* GLIBC headers included first so don't define anything
58 * that would already be defined. */
59
60 #define __UAPI_DEF_IF_IFCONF 0
61 #define __UAPI_DEF_IF_IFMAP 0
62 #define __UAPI_DEF_IF_IFNAMSIZ 0
63 #define __UAPI_DEF_IF_IFREQ 0
64 /* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
65 #define __UAPI_DEF_IF_NET_DEVICE_FLAGS 0
66 /* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
67 #ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
68 #define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
69 #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
70
71 #else /* _NET_IF_H */
72
73 /* Linux headers included first, and we must define everything
74 * we need. The expectation is that glibc will check the
75 * __UAPI_DEF_* defines and adjust appropriately. */
76
77 #define __UAPI_DEF_IF_IFCONF 1
78 #define __UAPI_DEF_IF_IFMAP 1
79 #define __UAPI_DEF_IF_IFNAMSIZ 1
80 #define __UAPI_DEF_IF_IFREQ 1
81 /* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
82 #define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1
83 /* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
84 #define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
85
86 #endif /* _NET_IF_H */
87
88 /* Coordinate with glibc netinet/in.h header. */
89 #if defined(_NETINET_IN_H)
90
91 /* GLIBC headers included first so don't define anything
92 * that would already be defined. */
93 #define __UAPI_DEF_IN_ADDR 0
94 #define __UAPI_DEF_IN_IPPROTO 0
95 #define __UAPI_DEF_IN_PKTINFO 0
96 #define __UAPI_DEF_IP_MREQ 0
97 #define __UAPI_DEF_SOCKADDR_IN 0
98 #define __UAPI_DEF_IN_CLASS 0
99
100 #define __UAPI_DEF_IN6_ADDR 0
101 /* The exception is the in6_addr macros which must be defined
102 * if the glibc code didn't define them. This guard matches
103 * the guard in glibc/inet/netinet/in.h which defines the
104 * additional in6_addr macros e.g. s6_addr16, and s6_addr32. */
105 #if defined(__USE_MISC) || defined (__USE_GNU)
106 #define __UAPI_DEF_IN6_ADDR_ALT 0
107 #else
108 #define __UAPI_DEF_IN6_ADDR_ALT 1
109 #endif
110 #define __UAPI_DEF_SOCKADDR_IN6 0
111 #define __UAPI_DEF_IPV6_MREQ 0
112 #define __UAPI_DEF_IPPROTO_V6 0
113 #define __UAPI_DEF_IPV6_OPTIONS 0
114 #define __UAPI_DEF_IN6_PKTINFO 0
115 #define __UAPI_DEF_IP6_MTUINFO 0
116
117 #else
118
119 /* Linux headers included first, and we must define everything
120 * we need. The expectation is that glibc will check the
121 * __UAPI_DEF_* defines and adjust appropriately. */
122 #define __UAPI_DEF_IN_ADDR 1
123 #define __UAPI_DEF_IN_IPPROTO 1
124 #define __UAPI_DEF_IN_PKTINFO 1
125 #define __UAPI_DEF_IP_MREQ 1
126 #define __UAPI_DEF_SOCKADDR_IN 1
127 #define __UAPI_DEF_IN_CLASS 1
128
129 #define __UAPI_DEF_IN6_ADDR 1
130 /* We unconditionally define the in6_addr macros and glibc must
131 * coordinate. */
132 #define __UAPI_DEF_IN6_ADDR_ALT 1
133 #define __UAPI_DEF_SOCKADDR_IN6 1
134 #define __UAPI_DEF_IPV6_MREQ 1
135 #define __UAPI_DEF_IPPROTO_V6 1
136 #define __UAPI_DEF_IPV6_OPTIONS 1
137 #define __UAPI_DEF_IN6_PKTINFO 1
138 #define __UAPI_DEF_IP6_MTUINFO 1
139
140 #endif /* _NETINET_IN_H */
141
142 /* Coordinate with glibc netipx/ipx.h header. */
143 #if defined(__NETIPX_IPX_H)
144
145 #define __UAPI_DEF_SOCKADDR_IPX 0
146 #define __UAPI_DEF_IPX_ROUTE_DEFINITION 0
147 #define __UAPI_DEF_IPX_INTERFACE_DEFINITION 0
148 #define __UAPI_DEF_IPX_CONFIG_DATA 0
149 #define __UAPI_DEF_IPX_ROUTE_DEF 0
150
151 #else /* defined(__NETIPX_IPX_H) */
152
153 #define __UAPI_DEF_SOCKADDR_IPX 1
154 #define __UAPI_DEF_IPX_ROUTE_DEFINITION 1
155 #define __UAPI_DEF_IPX_INTERFACE_DEFINITION 1
156 #define __UAPI_DEF_IPX_CONFIG_DATA 1
157 #define __UAPI_DEF_IPX_ROUTE_DEF 1
158
159 #endif /* defined(__NETIPX_IPX_H) */
160
161 /* Definitions for xattr.h */
162 #if defined(_SYS_XATTR_H)
163 #define __UAPI_DEF_XATTR 0
164 #else
165 #define __UAPI_DEF_XATTR 1
166 #endif
167
168 /* If we did not see any headers from any supported C libraries,
169 * or we are being included in the kernel, then define everything
170 * that we need. Check for previous __UAPI_* definitions to give
171 * unsupported C libraries a way to opt out of any kernel definition. */
172 #else /* !defined(__GLIBC__) */
173
174 /* Definitions for if.h */
175 #ifndef __UAPI_DEF_IF_IFCONF
176 #define __UAPI_DEF_IF_IFCONF 1
177 #endif
178 #ifndef __UAPI_DEF_IF_IFMAP
179 #define __UAPI_DEF_IF_IFMAP 1
180 #endif
181 #ifndef __UAPI_DEF_IF_IFNAMSIZ
182 #define __UAPI_DEF_IF_IFNAMSIZ 1
183 #endif
184 #ifndef __UAPI_DEF_IF_IFREQ
185 #define __UAPI_DEF_IF_IFREQ 1
186 #endif
187 /* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
188 #ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS
189 #define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1
190 #endif
191 /* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
192 #ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
193 #define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
194 #endif
195
196 /* Definitions for in.h */
197 #ifndef __UAPI_DEF_IN_ADDR
198 #define __UAPI_DEF_IN_ADDR 1
199 #endif
200 #ifndef __UAPI_DEF_IN_IPPROTO
201 #define __UAPI_DEF_IN_IPPROTO 1
202 #endif
203 #ifndef __UAPI_DEF_IN_PKTINFO
204 #define __UAPI_DEF_IN_PKTINFO 1
205 #endif
206 #ifndef __UAPI_DEF_IP_MREQ
207 #define __UAPI_DEF_IP_MREQ 1
208 #endif
209 #ifndef __UAPI_DEF_SOCKADDR_IN
210 #define __UAPI_DEF_SOCKADDR_IN 1
211 #endif
212 #ifndef __UAPI_DEF_IN_CLASS
213 #define __UAPI_DEF_IN_CLASS 1
214 #endif
215
216 /* Definitions for in6.h */
217 #ifndef __UAPI_DEF_IN6_ADDR
218 #define __UAPI_DEF_IN6_ADDR 1
219 #endif
220 #ifndef __UAPI_DEF_IN6_ADDR_ALT
221 #define __UAPI_DEF_IN6_ADDR_ALT 1
222 #endif
223 #ifndef __UAPI_DEF_SOCKADDR_IN6
224 #define __UAPI_DEF_SOCKADDR_IN6 1
225 #endif
226 #ifndef __UAPI_DEF_IPV6_MREQ
227 #define __UAPI_DEF_IPV6_MREQ 1
228 #endif
229 #ifndef __UAPI_DEF_IPPROTO_V6
230 #define __UAPI_DEF_IPPROTO_V6 1
231 #endif
232 #ifndef __UAPI_DEF_IPV6_OPTIONS
233 #define __UAPI_DEF_IPV6_OPTIONS 1
234 #endif
235 #ifndef __UAPI_DEF_IN6_PKTINFO
236 #define __UAPI_DEF_IN6_PKTINFO 1
237 #endif
238 #ifndef __UAPI_DEF_IP6_MTUINFO
239 #define __UAPI_DEF_IP6_MTUINFO 1
240 #endif
241
242 /* Definitions for ipx.h */
243 #ifndef __UAPI_DEF_SOCKADDR_IPX
244 #define __UAPI_DEF_SOCKADDR_IPX 1
245 #endif
246 #ifndef __UAPI_DEF_IPX_ROUTE_DEFINITION
247 #define __UAPI_DEF_IPX_ROUTE_DEFINITION 1
248 #endif
249 #ifndef __UAPI_DEF_IPX_INTERFACE_DEFINITION
250 #define __UAPI_DEF_IPX_INTERFACE_DEFINITION 1
251 #endif
252 #ifndef __UAPI_DEF_IPX_CONFIG_DATA
253 #define __UAPI_DEF_IPX_CONFIG_DATA 1
254 #endif
255 #ifndef __UAPI_DEF_IPX_ROUTE_DEF
256 #define __UAPI_DEF_IPX_ROUTE_DEF 1
257 #endif
258
259 /* Definitions for xattr.h */
260 #ifndef __UAPI_DEF_XATTR
261 #define __UAPI_DEF_XATTR 1
262 #endif
263
264 #endif /* __GLIBC__ */
265
266 #endif /* _LIBC_COMPAT_H */
0 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
01 #ifndef __LINUX_NEIGHBOUR_H
12 #define __LINUX_NEIGHBOUR_H
23
1920 NDA_LLADDR,
2021 NDA_CACHEINFO,
2122 NDA_PROBES,
23 NDA_VLAN,
24 NDA_PORT,
25 NDA_VNI,
26 NDA_IFINDEX,
27 NDA_MASTER,
28 NDA_LINK_NETNSID,
29 NDA_SRC_VNI,
2230 __NDA_MAX
2331 };
2432
2937 */
3038
3139 #define NTF_USE 0x01
32 #define NTF_PROXY 0x08 /* == ATF_PUBL */
33 #define NTF_ROUTER 0x80
34
3540 #define NTF_SELF 0x02
3641 #define NTF_MASTER 0x04
42 #define NTF_PROXY 0x08 /* == ATF_PUBL */
43 #define NTF_EXT_LEARNED 0x10
44 #define NTF_OFFLOADED 0x20
45 #define NTF_ROUTER 0x80
3746
3847 /*
3948 * Neighbor Cache Entry States.
5362
5463 /* NUD_NOARP & NUD_PERMANENT are pseudostates, they never change
5564 and make no address resolution or NUD.
56 NUD_PERMANENT is also cannot be deleted by garbage collectors.
65 NUD_PERMANENT also cannot be deleted by garbage collectors.
5766 */
5867
5968 struct nda_cacheinfo {
99108 __u64 ndts_rcv_probes_ucast;
100109 __u64 ndts_periodic_gc_runs;
101110 __u64 ndts_forced_gc_runs;
111 __u64 ndts_table_fulls;
102112 };
103113
104114 enum {
119129 NDTPA_PROXY_QLEN, /* u32 */
120130 NDTPA_LOCKTIME, /* u64, msecs */
121131 NDTPA_QUEUE_LENBYTES, /* u32 */
132 NDTPA_MCAST_REPROBES, /* u32 */
133 NDTPA_PAD,
122134 __NDTPA_MAX
123135 };
124136 #define NDTPA_MAX (__NDTPA_MAX - 1)
151163 NDTA_PARMS, /* nested TLV NDTPA_* */
152164 NDTA_STATS, /* struct ndt_stats, read-only */
153165 NDTA_GC_INTERVAL, /* u64, msecs */
166 NDTA_PAD,
154167 __NDTA_MAX
155168 };
156169 #define NDTA_MAX (__NDTA_MAX - 1)
0 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
01 #ifndef __LINUX_NETLINK_H
12 #define __LINUX_NETLINK_H
23
4 #include <linux/kernel.h>
5 #include <linux/socket.h> /* for __kernel_sa_family_t */
36 #include <linux/types.h>
47
58 #define NETLINK_ROUTE 0 /* Routing/device hook */
2427 #define NETLINK_ECRYPTFS 19
2528 #define NETLINK_RDMA 20
2629 #define NETLINK_CRYPTO 21 /* Crypto layer */
30 #define NETLINK_SMC 22 /* SMC monitoring */
2731
2832 #define NETLINK_INET_DIAG NETLINK_SOCK_DIAG
2933
4650
4751 /* Flags values */
4852
49 #define NLM_F_REQUEST 1 /* It is request message. */
50 #define NLM_F_MULTI 2 /* Multipart message, terminated by NLMSG_DONE */
51 #define NLM_F_ACK 4 /* Reply with ack, with zero or error code */
52 #define NLM_F_ECHO 8 /* Echo this request */
53 #define NLM_F_DUMP_INTR 16 /* Dump was inconsistent due to sequence change */
53 #define NLM_F_REQUEST 0x01 /* It is request message. */
54 #define NLM_F_MULTI 0x02 /* Multipart message, terminated by NLMSG_DONE */
55 #define NLM_F_ACK 0x04 /* Reply with ack, with zero or error code */
56 #define NLM_F_ECHO 0x08 /* Echo this request */
57 #define NLM_F_DUMP_INTR 0x10 /* Dump was inconsistent due to sequence change */
58 #define NLM_F_DUMP_FILTERED 0x20 /* Dump was filtered as requested */
5459
5560 /* Modifiers to GET request */
5661 #define NLM_F_ROOT 0x100 /* specify tree root */
6469 #define NLM_F_CREATE 0x400 /* Create, if it does not exist */
6570 #define NLM_F_APPEND 0x800 /* Add to end of list */
6671
72 /* Modifiers to DELETE request */
73 #define NLM_F_NONREC 0x100 /* Do not delete recursively */
74
75 /* Flags for ACK message */
76 #define NLM_F_CAPPED 0x100 /* request was capped */
77 #define NLM_F_ACK_TLVS 0x200 /* extended ACK TVLs were included */
78
6779 /*
6880 4.4BSD ADD NLM_F_CREATE|NLM_F_EXCL
6981 4.4BSD CHANGE NLM_F_REPLACE
7688 #define NLMSG_ALIGNTO 4U
7789 #define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
7890 #define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
79 #define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(NLMSG_HDRLEN))
91 #define NLMSG_LENGTH(len) ((len) + NLMSG_HDRLEN)
8092 #define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
8193 #define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
8294 #define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
83 (struct nlmsghdr*)(void*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
95 (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
8496 #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
8597 (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
8698 (nlh)->nlmsg_len <= (len))
96108 struct nlmsgerr {
97109 int error;
98110 struct nlmsghdr msg;
99 };
100
101 #define NETLINK_ADD_MEMBERSHIP 1
102 #define NETLINK_DROP_MEMBERSHIP 2
103 #define NETLINK_PKTINFO 3
104 #define NETLINK_BROADCAST_ERROR 4
105 #define NETLINK_NO_ENOBUFS 5
111 /*
112 * followed by the message contents unless NETLINK_CAP_ACK was set
113 * or the ACK indicates success (error == 0)
114 * message length is aligned with NLMSG_ALIGN()
115 */
116 /*
117 * followed by TLVs defined in enum nlmsgerr_attrs
118 * if NETLINK_EXT_ACK was set
119 */
120 };
121
122 /**
123 * enum nlmsgerr_attrs - nlmsgerr attributes
124 * @NLMSGERR_ATTR_UNUSED: unused
125 * @NLMSGERR_ATTR_MSG: error message string (string)
126 * @NLMSGERR_ATTR_OFFS: offset of the invalid attribute in the original
127 * message, counting from the beginning of the header (u32)
128 * @NLMSGERR_ATTR_COOKIE: arbitrary subsystem specific cookie to
129 * be used - in the success case - to identify a created
130 * object or operation or similar (binary)
131 * @__NLMSGERR_ATTR_MAX: number of attributes
132 * @NLMSGERR_ATTR_MAX: highest attribute number
133 */
134 enum nlmsgerr_attrs {
135 NLMSGERR_ATTR_UNUSED,
136 NLMSGERR_ATTR_MSG,
137 NLMSGERR_ATTR_OFFS,
138 NLMSGERR_ATTR_COOKIE,
139
140 __NLMSGERR_ATTR_MAX,
141 NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1
142 };
143
144 #define NETLINK_ADD_MEMBERSHIP 1
145 #define NETLINK_DROP_MEMBERSHIP 2
146 #define NETLINK_PKTINFO 3
147 #define NETLINK_BROADCAST_ERROR 4
148 #define NETLINK_NO_ENOBUFS 5
149 #define NETLINK_RX_RING 6
150 #define NETLINK_TX_RING 7
151 #define NETLINK_LISTEN_ALL_NSID 8
152 #define NETLINK_LIST_MEMBERSHIPS 9
153 #define NETLINK_CAP_ACK 10
154 #define NETLINK_EXT_ACK 11
106155
107156 struct nl_pktinfo {
108157 __u32 group;
109158 };
159
160 struct nl_mmap_req {
161 unsigned int nm_block_size;
162 unsigned int nm_block_nr;
163 unsigned int nm_frame_size;
164 unsigned int nm_frame_nr;
165 };
166
167 struct nl_mmap_hdr {
168 unsigned int nm_status;
169 unsigned int nm_len;
170 __u32 nm_group;
171 /* credentials */
172 __u32 nm_pid;
173 __u32 nm_uid;
174 __u32 nm_gid;
175 };
176
177 enum nl_mmap_status {
178 NL_MMAP_STATUS_UNUSED,
179 NL_MMAP_STATUS_RESERVED,
180 NL_MMAP_STATUS_VALID,
181 NL_MMAP_STATUS_COPY,
182 NL_MMAP_STATUS_SKIP,
183 };
184
185 #define NL_MMAP_MSG_ALIGNMENT NLMSG_ALIGNTO
186 #define NL_MMAP_MSG_ALIGN(sz) __ALIGN_KERNEL(sz, NL_MMAP_MSG_ALIGNMENT)
187 #define NL_MMAP_HDRLEN NL_MMAP_MSG_ALIGN(sizeof(struct nl_mmap_hdr))
110188
111189 #define NET_MAJOR 36 /* Major 36 is reserved for networking */
112190
147225 #define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
148226 #define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr)))
149227
150
151 #endif /* __LINUX_NETLINK_H */
228 /* Generic 32 bitflags attribute content sent to the kernel.
229 *
230 * The value is a bitmap that defines the values being set
231 * The selector is a bitmask that defines which value is legit
232 *
233 * Examples:
234 * value = 0x0, and selector = 0x1
235 * implies we are selecting bit 1 and we want to set its value to 0.
236 *
237 * value = 0x2, and selector = 0x2
238 * implies we are selecting bit 2 and we want to set its value to 1.
239 *
240 */
241 struct nla_bitfield32 {
242 __u32 value;
243 __u32 selector;
244 };
245
246 #endif /* __LINUX_NETLINK_H */
0 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
01 #ifndef __LINUX_RTNETLINK_H
12 #define __LINUX_RTNETLINK_H
23
119120 RTM_SETDCB,
120121 #define RTM_SETDCB RTM_SETDCB
121122
123 RTM_NEWNETCONF = 80,
124 #define RTM_NEWNETCONF RTM_NEWNETCONF
125 RTM_DELNETCONF,
126 #define RTM_DELNETCONF RTM_DELNETCONF
127 RTM_GETNETCONF = 82,
128 #define RTM_GETNETCONF RTM_GETNETCONF
129
130 RTM_NEWMDB = 84,
131 #define RTM_NEWMDB RTM_NEWMDB
132 RTM_DELMDB = 85,
133 #define RTM_DELMDB RTM_DELMDB
134 RTM_GETMDB = 86,
135 #define RTM_GETMDB RTM_GETMDB
136
137 RTM_NEWNSID = 88,
138 #define RTM_NEWNSID RTM_NEWNSID
139 RTM_DELNSID = 89,
140 #define RTM_DELNSID RTM_DELNSID
141 RTM_GETNSID = 90,
142 #define RTM_GETNSID RTM_GETNSID
143
144 RTM_NEWSTATS = 92,
145 #define RTM_NEWSTATS RTM_NEWSTATS
146 RTM_GETSTATS = 94,
147 #define RTM_GETSTATS RTM_GETSTATS
148
149 RTM_NEWCACHEREPORT = 96,
150 #define RTM_NEWCACHEREPORT RTM_NEWCACHEREPORT
151
152 RTM_NEWCHAIN = 100,
153 #define RTM_NEWCHAIN RTM_NEWCHAIN
154 RTM_DELCHAIN,
155 #define RTM_DELCHAIN RTM_DELCHAIN
156 RTM_GETCHAIN,
157 #define RTM_GETCHAIN RTM_GETCHAIN
158
122159 __RTM_MAX,
123160 #define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1)
124161 };
140177
141178 /* Macros to handle rtattributes */
142179
143 #define RTA_ALIGNTO 4
180 #define RTA_ALIGNTO 4U
144181 #define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) )
145182 #define RTA_OK(rta,len) ((len) >= (int)sizeof(struct rtattr) && \
146183 (rta)->rta_len >= sizeof(struct rtattr) && \
147184 (rta)->rta_len <= (len))
148185 #define RTA_NEXT(rta,attrlen) ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
149 (struct rtattr*)(void*)(((char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
186 (struct rtattr*)(((char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
150187 #define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
151188 #define RTA_SPACE(len) RTA_ALIGN(RTA_LENGTH(len))
152189 #define RTA_DATA(rta) ((void*)(((char*)(rta)) + RTA_LENGTH(0)))
221258 #define RTPROT_XORP 14 /* XORP */
222259 #define RTPROT_NTK 15 /* Netsukuku */
223260 #define RTPROT_DHCP 16 /* DHCP client */
261 #define RTPROT_MROUTED 17 /* Multicast daemon */
262 #define RTPROT_BABEL 42 /* Babel daemon */
263 #define RTPROT_BGP 186 /* BGP Routes */
264 #define RTPROT_ISIS 187 /* ISIS Routes */
265 #define RTPROT_OSPF 188 /* OSPF Routes */
266 #define RTPROT_RIP 189 /* RIP Routes */
267 #define RTPROT_EIGRP 192 /* EIGRP Routes */
224268
225269 /* rtm_scope
226270
248292 #define RTM_F_CLONED 0x200 /* This route is cloned */
249293 #define RTM_F_EQUALIZE 0x400 /* Multipath equalizer: NI */
250294 #define RTM_F_PREFIX 0x800 /* Prefix addresses */
295 #define RTM_F_LOOKUP_TABLE 0x1000 /* set rtm_table to FIB lookup result */
296 #define RTM_F_FIB_MATCH 0x2000 /* return full fib lookup match */
251297
252298 /* Reserved table identifiers */
253299
282328 RTA_MP_ALGO, /* no longer used */
283329 RTA_TABLE,
284330 RTA_MARK,
331 RTA_MFC_STATS,
332 RTA_VIA,
333 RTA_NEWDST,
334 RTA_PREF,
335 RTA_ENCAP_TYPE,
336 RTA_ENCAP,
337 RTA_EXPIRES,
338 RTA_PAD,
339 RTA_UID,
340 RTA_TTL_PROPAGATE,
341 RTA_IP_PROTO,
342 RTA_SPORT,
343 RTA_DPORT,
285344 __RTA_MAX
286345 };
287346
288347 #define RTA_MAX (__RTA_MAX - 1)
289348
290 #define RTM_RTA(r) ((struct rtattr*)(void*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
349 #define RTM_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
291350 #define RTM_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct rtmsg))
292351
293352 /* RTM_MULTIPATH --- array of struct rtnexthop.
311370 #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
312371 #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
313372 #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
373 #define RTNH_F_OFFLOAD 8 /* offloaded route */
374 #define RTNH_F_LINKDOWN 16 /* carrier-down on nexthop */
375 #define RTNH_F_UNRESOLVED 32 /* The entry is unresolved (ipmr) */
376
377 #define RTNH_COMPARE_MASK (RTNH_F_DEAD | RTNH_F_LINKDOWN | RTNH_F_OFFLOAD)
314378
315379 /* Macros to handle hexthops */
316380
318382 #define RTNH_ALIGN(len) ( ((len)+RTNH_ALIGNTO-1) & ~(RTNH_ALIGNTO-1) )
319383 #define RTNH_OK(rtnh,len) ((rtnh)->rtnh_len >= sizeof(struct rtnexthop) && \
320384 ((int)(rtnh)->rtnh_len) <= (len))
321 #define RTNH_NEXT(rtnh) ((struct rtnexthop*)(void*)(((char*)(rtnh)) + RTNH_ALIGN((rtnh)->rtnh_len)))
385 #define RTNH_NEXT(rtnh) ((struct rtnexthop*)(((char*)(rtnh)) + RTNH_ALIGN((rtnh)->rtnh_len)))
322386 #define RTNH_LENGTH(len) (RTNH_ALIGN(sizeof(struct rtnexthop)) + (len))
323387 #define RTNH_SPACE(len) RTNH_ALIGN(RTNH_LENGTH(len))
324 #define RTNH_DATA(rtnh) ((struct rtattr*)(void*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
388 #define RTNH_DATA(rtnh) ((struct rtattr*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
325389
326390 /* RTM_CACHEINFO */
327391
371435 #define RTAX_RTO_MIN RTAX_RTO_MIN
372436 RTAX_INITRWND,
373437 #define RTAX_INITRWND RTAX_INITRWND
438 RTAX_QUICKACK,
439 #define RTAX_QUICKACK RTAX_QUICKACK
440 RTAX_CC_ALGO,
441 #define RTAX_CC_ALGO RTAX_CC_ALGO
442 RTAX_FASTOPEN_NO_COOKIE,
443 #define RTAX_FASTOPEN_NO_COOKIE RTAX_FASTOPEN_NO_COOKIE
374444 __RTAX_MAX
375445 };
376446
377447 #define RTAX_MAX (__RTAX_MAX - 1)
378448
379 #define RTAX_FEATURE_ECN 0x00000001
380 #define RTAX_FEATURE_SACK 0x00000002
381 #define RTAX_FEATURE_TIMESTAMP 0x00000004
382 #define RTAX_FEATURE_ALLFRAG 0x00000008
449 #define RTAX_FEATURE_ECN (1 << 0)
450 #define RTAX_FEATURE_SACK (1 << 1)
451 #define RTAX_FEATURE_TIMESTAMP (1 << 2)
452 #define RTAX_FEATURE_ALLFRAG (1 << 3)
453
454 #define RTAX_FEATURE_MASK (RTAX_FEATURE_ECN | RTAX_FEATURE_SACK | \
455 RTAX_FEATURE_TIMESTAMP | RTAX_FEATURE_ALLFRAG)
383456
384457 struct rta_session {
385458 __u8 proto;
400473
401474 __u32 spi;
402475 } u;
476 };
477
478 struct rta_mfc_stats {
479 __u64 mfcs_packets;
480 __u64 mfcs_bytes;
481 __u64 mfcs_wrong_if;
403482 };
404483
405484 /****
470549 int tcm_ifindex;
471550 __u32 tcm_handle;
472551 __u32 tcm_parent;
552 /* tcm_block_index is used instead of tcm_parent
553 * in case tcm_ifindex == TCM_IFINDEX_MAGIC_BLOCK
554 */
555 #define tcm_block_index tcm_parent
473556 __u32 tcm_info;
474557 };
558
559 /* For manipulation of filters in shared block, tcm_ifindex is set to
560 * TCM_IFINDEX_MAGIC_BLOCK, and tcm_parent is aliased to tcm_block_index
561 * which is the block index.
562 */
563 #define TCM_IFINDEX_MAGIC_BLOCK (0xFFFFFFFFU)
475564
476565 enum {
477566 TCA_UNSPEC,
483572 TCA_FCNT,
484573 TCA_STATS2,
485574 TCA_STAB,
575 TCA_PAD,
576 TCA_DUMP_INVISIBLE,
577 TCA_CHAIN,
578 TCA_HW_OFFLOAD,
579 TCA_INGRESS_BLOCK,
580 TCA_EGRESS_BLOCK,
486581 __TCA_MAX
487582 };
488583
489584 #define TCA_MAX (__TCA_MAX - 1)
490585
491 #define TCA_RTA(r) ((struct rtattr*)(void*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
586 #define TCA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
492587 #define TCA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcmsg))
493588
494589 /********************************************************************
584679 #define RTNLGRP_PHONET_ROUTE RTNLGRP_PHONET_ROUTE
585680 RTNLGRP_DCB,
586681 #define RTNLGRP_DCB RTNLGRP_DCB
682 RTNLGRP_IPV4_NETCONF,
683 #define RTNLGRP_IPV4_NETCONF RTNLGRP_IPV4_NETCONF
684 RTNLGRP_IPV6_NETCONF,
685 #define RTNLGRP_IPV6_NETCONF RTNLGRP_IPV6_NETCONF
686 RTNLGRP_MDB,
687 #define RTNLGRP_MDB RTNLGRP_MDB
688 RTNLGRP_MPLS_ROUTE,
689 #define RTNLGRP_MPLS_ROUTE RTNLGRP_MPLS_ROUTE
690 RTNLGRP_NSID,
691 #define RTNLGRP_NSID RTNLGRP_NSID
692 RTNLGRP_MPLS_NETCONF,
693 #define RTNLGRP_MPLS_NETCONF RTNLGRP_MPLS_NETCONF
694 RTNLGRP_IPV4_MROUTE_R,
695 #define RTNLGRP_IPV4_MROUTE_R RTNLGRP_IPV4_MROUTE_R
696 RTNLGRP_IPV6_MROUTE_R,
697 #define RTNLGRP_IPV6_MROUTE_R RTNLGRP_IPV6_MROUTE_R
587698 __RTNLGRP_MAX
588699 };
589700 #define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
594705 unsigned char tca__pad1;
595706 unsigned short tca__pad2;
596707 };
597 #define TA_RTA(r) ((struct rtattr*)(void*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcamsg))))
708
709 enum {
710 TCA_ROOT_UNSPEC,
711 TCA_ROOT_TAB,
712 #define TCA_ACT_TAB TCA_ROOT_TAB
713 #define TCAA_MAX TCA_ROOT_TAB
714 TCA_ROOT_FLAGS,
715 TCA_ROOT_COUNT,
716 TCA_ROOT_TIME_DELTA, /* in msecs */
717 __TCA_ROOT_MAX,
718 #define TCA_ROOT_MAX (__TCA_ROOT_MAX - 1)
719 };
720
721 #define TA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcamsg))))
598722 #define TA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcamsg))
599 #define TCA_ACT_TAB 1 /* attr type must be >=1 */
600 #define TCAA_MAX 1
723 /* tcamsg flags stored in attribute TCA_ROOT_FLAGS
724 *
725 * TCA_FLAG_LARGE_DUMP_ON user->kernel to request for larger than TCA_ACT_MAX_PRIO
726 * actions in a dump. All dump responses will contain the number of actions
727 * being dumped stored in for user app's consumption in TCA_ROOT_COUNT
728 *
729 */
730 #define TCA_FLAG_LARGE_DUMP_ON (1 << 0)
601731
602732 /* New extended info filters for IFLA_EXT_MASK */
603733 #define RTEXT_FILTER_VF (1 << 0)
734 #define RTEXT_FILTER_BRVLAN (1 << 1)
735 #define RTEXT_FILTER_BRVLAN_COMPRESSED (1 << 2)
736 #define RTEXT_FILTER_SKIP_STATS (1 << 3)
604737
605738 /* End of information exported to user level */
606739
607740
608741
609 #endif /* __LINUX_RTNETLINK_H */
742 #endif /* __LINUX_RTNETLINK_H */
0 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
01 /*
12 * INET An implementation of the TCP/IP protocol suite for the LINUX
23 * operating system. INET is implemented using the BSD Socket
2324 #define SIOCINQ FIONREAD
2425 #define SIOCOUTQ TIOCOUTQ /* output queue size (not sent + not acked) */
2526
27 #define SOCK_IOC_TYPE 0x89
28
2629 /* Routing table calls. */
2730 #define SIOCADDRT 0x890B /* add routing table entry */
2831 #define SIOCDELRT 0x890C /* delete routing table entry */
29 #define SIOCRTMSG 0x890D /* call to routing system */
32 #define SIOCRTMSG 0x890D /* unused */
3033
3134 /* Socket configuration controls. */
3235 #define SIOCGIFNAME 0x8910 /* get iface name */
8386 #define SIOCWANDEV 0x894A /* get/set netdev parameters */
8487
8588 #define SIOCOUTQNSD 0x894B /* output queue size (not sent only) */
89 #define SIOCGSKNS 0x894C /* get socket network namespace */
8690
8791 /* ARP cache control calls. */
8892 /* 0x8950 - 0x8952 * obsolete calls, don't re-use */
124128 #define SIOCBRDELIF 0x89a3 /* remove interface from bridge */
125129
126130 /* hardware time stamping: parameters in linux/net_tstamp.h */
127 #define SIOCSHWTSTAMP 0x89b0
131 #define SIOCSHWTSTAMP 0x89b0 /* set and get config */
132 #define SIOCGHWTSTAMP 0x89b1 /* get config */
128133
129134 /* Device private ioctl calls */
130135
0 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
01 #ifndef _LINUX_TYPES_H
12 #define _LINUX_TYPES_H
23
1718 #else
1819 #define __bitwise__
1920 #endif
20 #ifdef __CHECK_ENDIAN__
2121 #define __bitwise __bitwise__
22 #else
23 #define __bitwise
24 #endif
2522
2623 typedef __u16 __bitwise __le16;
2724 typedef __u16 __bitwise __be16;
4643 #define __aligned_be64 __be64 __attribute__((aligned(8)))
4744 #define __aligned_le64 __le64 __attribute__((aligned(8)))
4845
46 typedef unsigned __bitwise __poll_t;
47
4948 #endif /* __ASSEMBLY__ */
5049 #endif /* _LINUX_TYPES_H */
0 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
01 /*
12 * This file define a set of standard wireless extensions
23 *
669670 /*
670671 * Generic format for most parameters that fit in an int
671672 */
672 struct iw_param
673 {
673 struct iw_param {
674674 __s32 value; /* The value of the parameter itself */
675675 __u8 fixed; /* Hardware should not use auto select */
676676 __u8 disabled; /* Disable the feature */
681681 * For all data larger than 16 octets, we need to use a
682682 * pointer to memory allocated in user space.
683683 */
684 struct iw_point
685 {
684 struct iw_point {
686685 void *pointer; /* Pointer to the data (in user space) */
687686 __u16 length; /* number of fields or size in bytes */
688687 __u16 flags; /* Optional params */
697696 * of 10 to get 'm' lower than 10^9, with 'm'= f / (10^'e')...
698697 * The power of 10 is in 'e', the result of the division is in 'm'.
699698 */
700 struct iw_freq
701 {
699 struct iw_freq {
702700 __s32 m; /* Mantissa */
703701 __s16 e; /* Exponent */
704702 __u8 i; /* List index (when in range struct) */
708706 /*
709707 * Quality of the link
710708 */
711 struct iw_quality
712 {
709 struct iw_quality {
713710 __u8 qual; /* link quality (%retries, SNR,
714711 %missed beacons or better...) */
715712 __u8 level; /* signal level (dBm) */
724721 * is already pretty exhaustive, and you should use that first.
725722 * This is only additional stats...
726723 */
727 struct iw_discarded
728 {
724 struct iw_discarded {
729725 __u32 nwid; /* Rx : Wrong nwid/essid */
730726 __u32 code; /* Rx : Unable to code/decode (WEP) */
731727 __u32 fragment; /* Rx : Can't perform MAC reassembly */
737733 * Packet/Time period missed in the wireless adapter due to
738734 * "wireless" specific problems...
739735 */
740 struct iw_missed
741 {
736 struct iw_missed {
742737 __u32 beacon; /* Missed beacons/superframe */
743738 };
744739
745740 /*
746741 * Quality range (for spy threshold)
747742 */
748 struct iw_thrspy
749 {
743 struct iw_thrspy {
750744 struct sockaddr addr; /* Source address (hw/mac) */
751745 struct iw_quality qual; /* Quality of the link */
752746 struct iw_quality low; /* Low threshold */
764758 * Especially, scan results are required to include an entry for the
765759 * current BSS if the driver is in Managed mode and associated with an AP.
766760 */
767 struct iw_scan_req
768 {
761 struct iw_scan_req {
769762 __u8 scan_type; /* IW_SCAN_TYPE_{ACTIVE,PASSIVE} */
770763 __u8 essid_len;
771764 __u8 num_channels; /* num entries in channel_list;
826819 * RX_SEQ_VALID for SIOCGIWENCODEEXT are optional, but can be useful for
827820 * debugging/testing.
828821 */
829 struct iw_encode_ext
830 {
822 struct iw_encode_ext {
831823 __u32 ext_flags; /* IW_ENCODE_EXT_* */
832824 __u8 tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
833825 __u8 rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
840832 };
841833
842834 /* SIOCSIWMLME data */
843 struct iw_mlme
844 {
835 struct iw_mlme {
845836 __u16 cmd; /* IW_MLME_* */
846837 __u16 reason_code;
847838 struct sockaddr addr;
854845
855846 #define IW_PMKID_LEN 16
856847
857 struct iw_pmksa
858 {
848 struct iw_pmksa {
859849 __u32 cmd; /* IW_PMKSA_* */
860850 struct sockaddr bssid;
861851 __u8 pmkid[IW_PMKID_LEN];
862852 };
863853
864854 /* IWEVMICHAELMICFAILURE data */
865 struct iw_michaelmicfailure
866 {
855 struct iw_michaelmicfailure {
867856 __u32 flags;
868857 struct sockaddr src_addr;
869858 __u8 tsc[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
871860
872861 /* IWEVPMKIDCAND data */
873862 #define IW_PMKID_CAND_PREAUTH 0x00000001 /* RNS pre-authentication enabled */
874 struct iw_pmkid_cand
875 {
863 struct iw_pmkid_cand {
876864 __u32 flags; /* IW_PMKID_CAND_* */
877865 __u32 index; /* the smaller the index, the higher the
878866 * priority */
883871 /*
884872 * Wireless statistics (used for /proc/net/wireless)
885873 */
886 struct iw_statistics
887 {
874 struct iw_statistics {
888875 __u16 status; /* Status
889876 * - device dependent for now */
890877
896883
897884 /* ------------------------ IOCTL REQUEST ------------------------ */
898885 /*
899 * This structure defines the payload of an ioctl, and is used
886 * This structure defines the payload of an ioctl, and is used
900887 * below.
901888 *
902889 * Note that this structure should fit on the memory footprint
905892 * You should check this when increasing the structures defined
906893 * above in this file...
907894 */
908 union iwreq_data
909 {
895 union iwreq_data {
910896 /* Config - generic */
911897 char name[IFNAMSIZ];
912898 /* Name : used to verify the presence of wireless extensions.
943929 * convenience...
944930 * Do I need to remind you about structure size (32 octets) ?
945931 */
946 struct iwreq
947 {
932 struct iwreq {
948933 union
949934 {
950935 char ifrn_name[IFNAMSIZ]; /* if name, e.g. "eth0" */
951936 } ifr_ifrn;
952937
953938 /* Data part (defined just above) */
954 union iwreq_data u;
939 union iwreq_data u;
955940 };
956941
957942 /* -------------------------- IOCTL DATA -------------------------- */
964949 * Range of parameters
965950 */
966951
967 struct iw_range
968 {
952 struct iw_range {
969953 /* Informative stuff (to choose between different interface) */
970954 __u32 throughput; /* To give an idea... */
971955 /* In theory this value should be the maximum benchmarked
10681052 /*
10691053 * Private ioctl interface information
10701054 */
1071
1072 struct iw_priv_args
1073 {
1055
1056 struct iw_priv_args {
10741057 __u32 cmd; /* Number of the ioctl to issue */
10751058 __u16 set_args; /* Type and number of args */
10761059 __u16 get_args; /* Type and number of args */
10871070 /*
10881071 * A Wireless Event. Contains basically the same data as the ioctl...
10891072 */
1090 struct iw_event
1091 {
1073 struct iw_event {
10921074 __u16 len; /* Real length of this stuff */
10931075 __u16 cmd; /* Wireless IOCTL */
10941076 union iwreq_data u; /* IOCTL fixed payload */
11241106 #define IW_EV_QUAL_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct iw_quality))
11251107 #define IW_EV_POINT_PK_LEN (IW_EV_LCP_PK_LEN + 4)
11261108
1127 #endif /* _LINUX_WIRELESS_H */
1109 #endif /* _LINUX_WIRELESS_H */
6161 #endif
6262 #undef NEWLINE
6363
64 extern const char *ctlname;
65
6466 /* commands.c */
6567 #define NEWLINE "<CR>"
6668 struct cmd_node;
7577 struct cmd_env*, void *),
7678 void *);
7779 struct cmd_node* commands_privileged(struct cmd_node *);
80 struct cmd_node* commands_lock(struct cmd_node *);
7881 struct cmd_node* commands_hidden(struct cmd_node *);
7982 void commands_free(struct cmd_node *);
8083 const char *cmdenv_arg(struct cmd_env*);
1717 #include "client.h"
1818 #include <string.h>
1919 #include <sys/queue.h>
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <sys/un.h>
2023
2124 /**
2225 * An element of the environment (a key and a value).
6770 const char *token; /**< Token to enter this cnode */
6871 const char *doc; /**< Documentation string */
6972 int privileged; /**< Privileged command? */
73 int lock; /**< Lock required for execution? */
7074 int hidden; /**< Hidden command? */
7175
7276 /**
113117 }
114118
115119 /**
120 * Make a node accessible only with a lock.
121 *
122 * @param node node to use lock to execute
123 * @return the modified node
124 *
125 * The node is modified. It is returned to ease chaining.
126 */
127 struct cmd_node*
128 commands_lock(struct cmd_node *node)
129 {
130 if (node) node->lock = 1;
131 return node;
132 }
133
134 /**
116135 * Hide a node from help or completion.
117136 *
118137 * @param node node to hide
343362 int n, rc = 0, completion = (word != NULL);
344363 int help = 0; /* Are we asking for help? */
345364 int complete = 0; /* Are we asking for possible completions? */
365 int needlock = 0; /* Do we need a lock? */
346366 struct cmd_env env = {
347367 .elements = TAILQ_HEAD_INITIALIZER(env.elements),
348368 .stack = TAILQ_HEAD_INITIALIZER(env.stack),
350370 .argv = argv,
351371 .argp = 0
352372 };
373 static int lockfd = -1;
353374 cmdenv_push(&env, root);
354375 if (!completion)
355376 for (n = 0; n < argc; n++)
387408 !strcmp(candidate->token, token)) {
388409 /* Exact match */
389410 best = candidate;
411 needlock = needlock || candidate->lock;
390412 break;
391413 }
392414 if (!best) best = candidate;
405427 if (!candidate->token &&
406428 CAN_EXECUTE(candidate)) {
407429 best = candidate;
430 needlock = needlock || candidate->lock;
408431 break;
409432 }
410433 }
420443
421444 /* Push and execute */
422445 cmdenv_push(&env, best);
423 if (best->execute && best->execute(conn, w, &env, best->arg) != 1) {
424 rc = -1;
425 goto end;
446 if (best->execute) {
447 struct sockaddr_un su;
448 if (needlock) {
449 if (lockfd == -1) {
450 log_debug("lldpctl", "reopen %s for locking", ctlname);
451 if ((lockfd = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) {
452 log_warn("lldpctl", "cannot open for lock %s", ctlname);
453 rc = -1;
454 goto end;
455 }
456 su.sun_family = AF_UNIX;
457 strlcpy(su.sun_path, ctlname, sizeof(su.sun_path));
458 if (connect(lockfd, (struct sockaddr *)&su, sizeof(struct sockaddr_un)) == -1) {
459 log_warn("lldpctl", "cannot connect to socket %s", ctlname);
460 rc = -1;
461 close(lockfd); lockfd = -1;
462 goto end;
463 }
464 }
465 if (lockf(lockfd, F_LOCK, 0) == -1) {
466 log_warn("lldpctl", "cannot get lock on %s", ctlname);
467 rc = -1;
468 close(lockfd); lockfd = -1;
469 goto end;
470 }
471 }
472 rc = best->execute(conn, w, &env, best->arg) != 1 ? -1 : rc;
473 if (needlock && lockf(lockfd, F_ULOCK, 0) == -1) {
474 log_warn("lldpctl", "cannot unlock %s", ctlname);
475 close(lockfd); lockfd = -1;
476 }
477 if (rc == -1) goto end;
426478 }
427479 env.argp++;
428480 }
2525 cmd_txdelay(struct lldpctl_conn_t *conn, struct writer *w,
2626 struct cmd_env *env, void *arg)
2727 {
28 const char *interval;
29 char interval_ms[8]; /* less than 2.5 hours */
30 lldpctl_key_t key;
31 int arglen;
32
2833 log_debug("lldpctl", "set transmit delay");
2934
3035 lldpctl_atom_t *config = lldpctl_get_configuration(conn);
3338 lldpctl_last_strerror(conn));
3439 return 0;
3540 }
36 if (lldpctl_atom_set_str(config,
37 lldpctl_k_config_tx_interval, cmdenv_get(env, "tx-interval")) == NULL) {
41 interval = cmdenv_get(env, "tx-interval");
42 key = lldpctl_k_config_tx_interval;
43 /* interval is either <number> for seconds or <number>ms for milliseconds */
44 if (interval) {
45 arglen = strlen(interval);
46 /* room for "ms" in interval, room for interval in interval_ms */
47 if (arglen >= 2 && arglen-2 < sizeof(interval_ms) &&
48 strcmp("ms", interval+arglen-2) == 0) {
49 /* remove "ms" suffix */
50 memcpy(interval_ms, interval, arglen-2);
51 interval_ms[arglen-2] = '\0';
52 /* substitute key and value */
53 key = lldpctl_k_config_tx_interval_ms;
54 interval = interval_ms;
55 }
56 }
57 if (lldpctl_atom_set_str(config, key, interval) == NULL) {
3858 log_warnx("lldpctl", "unable to set transmit delay. %s",
3959 lldpctl_last_strerror(conn));
4060 lldpctl_atom_dec_ref(config);
520540 commands_new(configure_lldp,
521541 "tx-interval", "Set LLDP transmit delay",
522542 cmd_check_no_env, NULL, "ports"),
523 NULL, "LLDP transmit delay in seconds",
543 NULL, "LLDP transmit <delay> in seconds or <delay>ms in milliseconds",
524544 NULL, cmd_store_env_value, "tx-interval"),
525545 NEWLINE, "Set LLDP transmit delay",
526546 NULL, cmd_txdelay, NULL);
120120 /* Powerpairs */
121121 (what = "power pairs", lldpctl_atom_set_str(dot3_power,
122122 lldpctl_k_dot3_power_pairs,
123 cmdenv_get(env, "powerpairs"))) == NULL ||
123 cmdenv_get(env, "powerpairs")?cmdenv_get(env, "powerpairs"):"unknown")) == NULL ||
124124 /* Class */
125125 (what = "power class", cmdenv_get(env, "class")?
126126 lldpctl_atom_set_str(dot3_power,
303303 static int
304304 cmd_check_env_power(struct cmd_env *env, void *nothing)
305305 {
306 /* We need type and powerpair but if we have typeat, we also request
307 * source, priority, requested and allocated. */
306 /* We need type. If we type is PSE, we need powerpairs. If we have
307 * typeat, we also request source, priority, requested and allocated. */
308308 if (!cmdenv_get(env, "device-type")) return 0;
309 if (!cmdenv_get(env, "powerpairs")) return 0;
309 if (!strcmp(cmdenv_get(env, "device-type"), "pse") &&
310 !cmdenv_get(env, "powerpairs")) return 0;
310311 if (cmdenv_get(env, "typeat")) {
311312 return (!!cmdenv_get(env, "source") &&
312313 !!cmdenv_get(env, "priority") &&
359360 /* Power pairs */
360361 struct cmd_node *powerpairs = commands_new(
361362 configure_dot3power,
362 "powerpairs", "Which pairs are currently used for power (mandatory)",
363 cmd_check_type_but_no, NULL, "powerpairs");
363 "powerpairs", "Which pairs are currently used for power",
364 cmd_check_pse, NULL, "powerpairs");
364365 for (lldpctl_map_t *pp_map =
365366 lldpctl_key_get_map(lldpctl_k_dot3_power_pairs);
366367 pp_map->string;
3636 "unconfigure",
3737 "Unconfigure system settings",
3838 NULL, NULL, NULL);
39 commands_privileged(configure);
40 commands_privileged(unconfigure);
39 commands_privileged(commands_lock(configure));
40 commands_privileged(commands_lock(unconfigure));
4141 cmd_restrict_ports(configure);
4242 cmd_restrict_ports(unconfigure);
4343
257257 lldpctl_atom_foreach(mgmts, mgmt) {
258258 tag_datatag(w, "mgmt-ip", "MgmtIP",
259259 lldpctl_atom_get_str(mgmt, lldpctl_k_mgmt_ip));
260 if (lldpctl_atom_get_int(mgmt, lldpctl_k_mgmt_iface_index))
261 tag_datatag(w, "mgmt-iface", "MgmtIface",
262 lldpctl_atom_get_str(mgmt, lldpctl_k_mgmt_iface_index));
260263 }
261264 lldpctl_atom_dec_ref(mgmts);
262265
427430 tag_data(w, lldpctl_atom_get_str(dot3_power,
428431 lldpctl_k_dot3_power_devicetype));;
429432 tag_end(w);
430 tag_start(w, "pairs", "Power pairs");
431 tag_data(w, lldpctl_atom_get_str(dot3_power,
432 lldpctl_k_dot3_power_pairs));
433 tag_end(w);
433 if (lldpctl_atom_get_int(dot3_power,
434 lldpctl_k_dot3_power_devicetype) == LLDP_DOT3_POWER_PSE) {
435 tag_start(w, "pairs", "Power pairs");
436 tag_data(w, lldpctl_atom_get_str(dot3_power,
437 lldpctl_k_dot3_power_pairs));
438 tag_end(w);
439 }
434440 tag_start(w, "class", "Class");
435441 tag_data(w, lldpctl_atom_get_str(dot3_power,
436442 lldpctl_k_dot3_power_class));
462468 tag_start(w, "allocated", "PSE allocated power Value");
463469 tag_data(w, lldpctl_atom_get_str(dot3_power,
464470 lldpctl_k_dot3_power_allocated));
471 tag_end(w);
472 }
473
474 /* 802.3bt */
475 if (lldpctl_atom_get_int(dot3_power,
476 lldpctl_k_dot3_power_type_ext) > LLDP_DOT3_POWER_8023BT_OFF) {
477 tag_start(w, "requested-a", "Requested mode A");
478 tag_data(w, lldpctl_atom_get_str(dot3_power,
479 lldpctl_k_dot3_power_requested_a));
480 tag_end(w);
481 tag_start(w, "requested-b", "Requested mode B");
482 tag_data(w, lldpctl_atom_get_str(dot3_power,
483 lldpctl_k_dot3_power_requested_b));
484 tag_end(w);
485 tag_start(w, "allocated-a", "Allocated alternative A");
486 tag_data(w, lldpctl_atom_get_str(dot3_power,
487 lldpctl_k_dot3_power_allocated_a));
488 tag_end(w);
489 tag_start(w, "allocated-b", "Allocated alternative B");
490 tag_data(w, lldpctl_atom_get_str(dot3_power,
491 lldpctl_k_dot3_power_allocated_b));
492 tag_end(w);
493 tag_start(w, "pse-powering-status", "PSE powering status");
494 tag_data(w, lldpctl_atom_get_str(dot3_power,
495 lldpctl_k_dot3_power_pse_status));
496 tag_end(w);
497 tag_start(w, "pd-powering-status", "PD powering status");
498 tag_data(w, lldpctl_atom_get_str(dot3_power,
499 lldpctl_k_dot3_power_pd_status));
500 tag_end(w);
501 tag_start(w, "power-pairs-ext", "Power pairs extra");
502 tag_data(w, lldpctl_atom_get_str(dot3_power,
503 lldpctl_k_dot3_power_pse_pairs_ext));
504 tag_end(w);
505 tag_start(w, "power-class-ext-a", "Class extra A");
506 tag_data(w, lldpctl_atom_get_str(dot3_power,
507 lldpctl_k_dot3_power_class_a));
508 tag_end(w);
509 tag_start(w, "power-class-ext-b", "Class extra B");
510 tag_data(w, lldpctl_atom_get_str(dot3_power,
511 lldpctl_k_dot3_power_class_b));
512 tag_end(w);
513 tag_start(w, "power-class-ext", "Class extra");
514 tag_data(w, lldpctl_atom_get_str(dot3_power,
515 lldpctl_k_dot3_power_class_ext));
516 tag_end(w);
517 tag_start(w, "power-type-ext", "Power type extra");
518 tag_data(w, lldpctl_atom_get_str(dot3_power,
519 lldpctl_k_dot3_power_type_ext));
520 tag_end(w);
521 tag_start(w, "pd-load", "PD load");
522 tag_data(w, lldpctl_atom_get_str(dot3_power,
523 lldpctl_k_dot3_power_pd_load));
524 tag_end(w);
525 tag_start(w, "max-power", "PSE maximum available power");
526 tag_data(w, lldpctl_atom_get_str(dot3_power,
527 lldpctl_k_dot3_power_pse_max));
465528 tag_end(w);
466529 }
467530
489552 }
490553
491554 tx_hold = lldpctl_atom_get_int(configuration, lldpctl_k_config_tx_hold);
492 tx_interval = lldpctl_atom_get_int(configuration, lldpctl_k_config_tx_interval);
493
494 if (asprintf(&ttl, "%lu", tx_hold*tx_interval) == -1) {
555 tx_interval = lldpctl_atom_get_int(configuration, lldpctl_k_config_tx_interval_ms);
556
557 tx_interval = (tx_interval * tx_hold + 999) / 1000;
558
559 if (asprintf(&ttl, "%lu", tx_interval) == -1) {
495560 log_warnx("lldpctl", "not enough memory to build TTL.");
496561 goto end;
497562 }
518583 lldpctl_atom_foreach(vlans, vlan) {
519584 vid = lldpctl_atom_get_int(vlan,
520585 lldpctl_k_vlan_id);
521 if (pvid == vid)
522 foundpvid = 1;
523586
524587 tag_start(w, "vlan", "VLAN");
525588 tag_attr(w, "vlan-id", "",
526589 lldpctl_atom_get_str(vlan, lldpctl_k_vlan_id));
527 if (pvid == vid)
590 if (pvid == vid) {
528591 tag_attr(w, "pvid", "pvid", "yes");
592 foundpvid = 1;
593 } else {
594 tag_attr(w, "pvid", "pvid", "no");
595 }
529596 tag_data(w, lldpctl_atom_get_str(vlan,
530597 lldpctl_k_vlan_name));
531598 tag_end(w);
667734 *
668735 * @param conn Connection to lldpd.
669736 * @param w Writer.
737 * @param env Environment from which we may find the list of ports.
670738 * @param hidden Whatever to show hidden ports.
671 * @param env Environment from which we may find the list of ports.
672739 * @param details Level of details we need (DISPLAY_*).
673740 */
674741 void
883950
884951 tag_datatag(w, "tx-delay", "Transmit delay",
885952 lldpctl_atom_get_str(configuration, lldpctl_k_config_tx_interval));
953 tag_datatag(w, "tx-delay-ms", "Transmit delay in milliseconds",
954 lldpctl_atom_get_str(configuration, lldpctl_k_config_tx_interval_ms));
886955 tag_datatag(w, "tx-hold", "Transmit hold",
887956 lldpctl_atom_get_str(configuration, lldpctl_k_config_tx_hold));
888957 tag_datatag(w, "max-neighbors", "Maximum number of neighbors",
390390 IPv4 and one IPv6 addresses are chosen. Otherwise, many of them can be
391391 selected. If you want to blacklist IPv6 addresses, you can use
392392 .Em !*:* .
393 If an interface name is matched, the first IPv4 address and the first
394 IPv6 address associated to this interface will be chosen.
393395 .Ed
394396
395397 .Cd unconfigure
501503 .Bd -ragged -offset XXXXXX
502504 Change transmit delay to the specified value in seconds. The transmit
503505 delay is the delay between two transmissions of LLDP PDU. The default
504 value is 30 seconds.
506 value is 30 seconds. Note:
507 .Nm lldpd
508 also starts another system based refresh timer on each port to detect
509 changes such as a hostname. This is the value of the tx-interval
510 multiplied by 20.
511 .Pp
512 You can specify an
513 .Cd interval
514 value in milliseconds by appending a "ms" suffix to the figure (e.g.
515 "configure lldp tx-interval 1500ms" is 1.5s, not 1500s). In this case
516 the TTL for received and sent LLDP frames is rounded up to the next
517 second. Note: the effective interval can be limited by the operating
518 system capabilities and CPU speed.
505519 .Ed
506520
507521 .Cd configure
891905 .Op Cd supported
892906 .Op Cd enabled
893907 .Op Cd paircontrol
894 .Cd powerpairs Ar powerpairs
908 .Op Cd powerpairs Ar powerpairs
895909 .Op Cd class Ar class
896910 .Op Cd type Ar type Cd source Ar source Cd priority Ar priority Cd requested Ar requested Cd allocated Ar allocated
897911 .Bd -ragged -offset XXXXXX
137137
138138 result = malloc(sizeof(struct writer));
139139 if (!result) {
140 fatalx("llpctl", "out of memory");
140 fatalx("lldpctl", "out of memory");
141141 free(priv);
142142 return NULL;
143143 }
1919 interfaces.c \
2020 event.c lldpd.c \
2121 pattern.c \
22 bitmap.c \
2223 probes.d trace.h \
2324 protocols/lldp.c \
2425 protocols/cdp.c \
208208 $(am__DEPENDENCIES_1) $(am__append_15)
209209 am__liblldpd_la_SOURCES_DIST = frame.h frame.c lldp-tlv.h client.c \
210210 priv.c privsep.c privsep_io.c privsep_fd.c interfaces.c \
211 event.c lldpd.c pattern.c probes.d trace.h protocols/lldp.c \
212 protocols/cdp.c protocols/cdp.h protocols/sonmp.c \
213 protocols/sonmp.h protocols/edp.c protocols/edp.h \
214 forward-linux.c interfaces-linux.c netlink.c dmi-linux.c \
215 priv-linux.c forward-bsd.c interfaces-bpf.c interfaces-bsd.c \
216 dmi-dummy.c priv-bsd.c dmi-freebsd.c dmi-openbsd.c dmi-osx.c \
217 forward-solaris.c interfaces-solaris.c priv-seccomp.c
211 event.c lldpd.c pattern.c bitmap.c probes.d trace.h \
212 protocols/lldp.c protocols/cdp.c protocols/cdp.h \
213 protocols/sonmp.c protocols/sonmp.h protocols/edp.c \
214 protocols/edp.h forward-linux.c interfaces-linux.c netlink.c \
215 dmi-linux.c priv-linux.c forward-bsd.c interfaces-bpf.c \
216 interfaces-bsd.c dmi-dummy.c priv-bsd.c dmi-freebsd.c \
217 dmi-openbsd.c dmi-osx.c forward-solaris.c interfaces-solaris.c \
218 priv-seccomp.c
218219 am__dirstamp = $(am__leading_dot)dirstamp
219220 @HOST_OS_LINUX_TRUE@am__objects_1 = liblldpd_la-forward-linux.lo \
220221 @HOST_OS_LINUX_TRUE@ liblldpd_la-interfaces-linux.lo \
257258 liblldpd_la-privsep_io.lo liblldpd_la-privsep_fd.lo \
258259 liblldpd_la-interfaces.lo liblldpd_la-event.lo \
259260 liblldpd_la-lldpd.lo liblldpd_la-pattern.lo \
260 protocols/liblldpd_la-lldp.lo protocols/liblldpd_la-cdp.lo \
261 protocols/liblldpd_la-sonmp.lo protocols/liblldpd_la-edp.lo \
262 $(am__objects_1) $(am__objects_2) $(am__objects_3) \
263 $(am__objects_4) $(am__objects_5) $(am__objects_6) \
264 $(am__objects_7) $(am__objects_8)
261 liblldpd_la-bitmap.lo protocols/liblldpd_la-lldp.lo \
262 protocols/liblldpd_la-cdp.lo protocols/liblldpd_la-sonmp.lo \
263 protocols/liblldpd_la-edp.lo $(am__objects_1) $(am__objects_2) \
264 $(am__objects_3) $(am__objects_4) $(am__objects_5) \
265 $(am__objects_6) $(am__objects_7) $(am__objects_8)
265266 am__objects_9 =
266267 nodist_liblldpd_la_OBJECTS = $(am__objects_9)
267268 liblldpd_la_OBJECTS = $(am_liblldpd_la_OBJECTS) \
291292 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
292293 depcomp = $(SHELL) $(top_srcdir)/depcomp
293294 am__maybe_remake_depfiles = depfiles
294 am__depfiles_remade = ./$(DEPDIR)/liblldpd_la-client.Plo \
295 am__depfiles_remade = ./$(DEPDIR)/liblldpd_la-bitmap.Plo \
296 ./$(DEPDIR)/liblldpd_la-client.Plo \
295297 ./$(DEPDIR)/liblldpd_la-dmi-dummy.Plo \
296298 ./$(DEPDIR)/liblldpd_la-dmi-freebsd.Plo \
297299 ./$(DEPDIR)/liblldpd_la-dmi-linux.Plo \
600602 nodist_liblldpd_la_SOURCES = $(am__append_10)
601603 liblldpd_la_SOURCES = frame.h frame.c lldp-tlv.h client.c priv.c \
602604 privsep.c privsep_io.c privsep_fd.c interfaces.c event.c \
603 lldpd.c pattern.c probes.d trace.h protocols/lldp.c \
605 lldpd.c pattern.c bitmap.c probes.d trace.h protocols/lldp.c \
604606 protocols/cdp.c protocols/cdp.h protocols/sonmp.c \
605607 protocols/sonmp.h protocols/edp.c protocols/edp.h \
606608 $(am__append_1) $(am__append_2) $(am__append_3) \
780782 distclean-compile:
781783 -rm -f *.tab.c
782784
785 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-bitmap.Plo@am__quote@ # am--include-marker
783786 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-client.Plo@am__quote@ # am--include-marker
784787 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-dmi-dummy.Plo@am__quote@ # am--include-marker
785788 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-dmi-freebsd.Plo@am__quote@ # am--include-marker
927930 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pattern.c' object='liblldpd_la-pattern.lo' libtool=yes @AMDEPBACKSLASH@
928931 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
929932 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-pattern.lo `test -f 'pattern.c' || echo '$(srcdir)/'`pattern.c
933
934 liblldpd_la-bitmap.lo: bitmap.c
935 @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-bitmap.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-bitmap.Tpo -c -o liblldpd_la-bitmap.lo `test -f 'bitmap.c' || echo '$(srcdir)/'`bitmap.c
936 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-bitmap.Tpo $(DEPDIR)/liblldpd_la-bitmap.Plo
937 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bitmap.c' object='liblldpd_la-bitmap.lo' libtool=yes @AMDEPBACKSLASH@
938 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
939 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-bitmap.lo `test -f 'bitmap.c' || echo '$(srcdir)/'`bitmap.c
930940
931941 protocols/liblldpd_la-lldp.lo: protocols/lldp.c
932942 @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT protocols/liblldpd_la-lldp.lo -MD -MP -MF protocols/$(DEPDIR)/liblldpd_la-lldp.Tpo -c -o protocols/liblldpd_la-lldp.lo `test -f 'protocols/lldp.c' || echo '$(srcdir)/'`protocols/lldp.c
13361346 clean-sbinPROGRAMS mostlyclean-am
13371347
13381348 distclean: distclean-am
1339 -rm -f ./$(DEPDIR)/liblldpd_la-client.Plo
1349 -rm -f ./$(DEPDIR)/liblldpd_la-bitmap.Plo
1350 -rm -f ./$(DEPDIR)/liblldpd_la-client.Plo
13401351 -rm -f ./$(DEPDIR)/liblldpd_la-dmi-dummy.Plo
13411352 -rm -f ./$(DEPDIR)/liblldpd_la-dmi-freebsd.Plo
13421353 -rm -f ./$(DEPDIR)/liblldpd_la-dmi-linux.Plo
14161427 installcheck-am:
14171428
14181429 maintainer-clean: maintainer-clean-am
1419 -rm -f ./$(DEPDIR)/liblldpd_la-client.Plo
1430 -rm -f ./$(DEPDIR)/liblldpd_la-bitmap.Plo
1431 -rm -f ./$(DEPDIR)/liblldpd_la-client.Plo
14201432 -rm -f ./$(DEPDIR)/liblldpd_la-dmi-dummy.Plo
14211433 -rm -f ./$(DEPDIR)/liblldpd_la-dmi-freebsd.Plo
14221434 -rm -f ./$(DEPDIR)/liblldpd_la-dmi-linux.Plo
638638
639639 switch (vp->magic) {
640640 case LLDP_SNMP_TXINTERVAL:
641 long_ret = scfg->g_config.c_tx_interval;
641 long_ret = (scfg->g_config.c_tx_interval+999) / 1000;
642642 return (u_char *)&long_ret;
643643 case LLDP_SNMP_TXMULTIPLIER:
644 long_ret = scfg->g_config.c_ttl / scfg->g_config.c_tx_interval;
644 long_ret = scfg->g_config.c_tx_hold;
645645 return (u_char *)&long_ret;
646646 case LLDP_SNMP_REINITDELAY:
647647 long_ret = 1;
3232 #include <net-snmp/agent/snmp_vars.h>
3333 #include <net-snmp/library/snmpUnixDomain.h>
3434
35 #ifdef ASN_PRIV_STOP
36 /* NetSNMP 5.8+ */
37 #define F_SEND_SIGNATURE netsnmp_transport *t, const void *buf, int size, void **opaque, int *olength
38 #define F_FMTADDR_SIGNATURE netsnmp_transport *t, const void *data, int len
39 #define F_FROM_OSTRING_SIGNATURE const void* o, size_t o_len, int local
40 #else
41 #define F_SEND_SIGNATURE netsnmp_transport *t, void *buf, int size, void **opaque, int *olength
42 #define F_FMTADDR_SIGNATURE netsnmp_transport *t, void *data, int len
43 #define F_FROM_OSTRING_SIGNATURE const u_char* o, size_t o_len, int local
44 #endif
45
3546 static oid netsnmp_unix[] = { TRANSPORT_DOMAIN_LOCAL };
3647 static netsnmp_tdomain unixDomain;
3748
3849 static char *
39 agent_priv_unix_fmtaddr(netsnmp_transport *t, void *data, int len)
50 agent_priv_unix_fmtaddr(F_FMTADDR_SIGNATURE)
4051 {
4152 /* We don't bother to implement the full function */
4253 return strdup("Local Unix socket with privilege separation: unknown");
7990
8091 #define AGENT_WRITE_TIMEOUT 2000
8192 static int
82 agent_priv_unix_send(netsnmp_transport *t, void *buf, int size,
83 void **opaque, int *olength)
93 agent_priv_unix_send(F_SEND_SIGNATURE)
8494 {
8595 int rc = -1;
8696
216226 }
217227
218228 static netsnmp_transport *
219 agent_priv_unix_create_ostring(const u_char * o, size_t o_len, int local)
229 agent_priv_unix_create_ostring(F_FROM_OSTRING_SIGNATURE)
220230 {
221231 return agent_priv_unix_transport((char *)o, o_len, local);
222232 }
0 /* -*- mode: c; c-file-style: "openbsd" -*- */
1 /*
2 * Copyright (c) 2020 Vincent Bernat <bernat@luffy.cx>
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 /* Helpers around bitmaps */
18
19 #include "lldpd.h"
20
21 /*
22 * Set vlan id in the bitmap
23 */
24 void
25 bitmap_set(uint32_t *bmap, uint16_t vlan_id)
26 {
27 if (vlan_id < MAX_VLAN)
28 bmap[vlan_id / 32] |= (((uint32_t) 1) << (vlan_id % 32));
29 }
30
31 /*
32 * Checks if the bitmap is empty
33 */
34 int
35 bitmap_isempty(uint32_t *bmap)
36 {
37 int i;
38
39 for (i = 0; i < VLAN_BITMAP_LEN; i++) {
40 if (bmap[i] != 0)
41 return 0;
42 }
43
44 return 1;
45 }
46
47 /*
48 * Calculate the number of bits set in the bitmap to get total
49 * number of VLANs
50 */
51 unsigned int
52 bitmap_numbits(uint32_t *bmap)
53 {
54 unsigned int num = 0;
55
56 for (int i = 0; (i < VLAN_BITMAP_LEN); i++) {
57 uint32_t v = bmap[i];
58 v = v - ((v >> 1) & 0x55555555);
59 v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
60 num += (((v + (v >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
61 }
62
63 return num;
64 }
7171 if (config->c_tx_interval < 0) {
7272 log_debug("rpc", "client asked for immediate retransmission");
7373 } else {
74 log_debug("rpc", "client change transmit interval to %d",
74 log_debug("rpc", "client change transmit interval to %d ms",
7575 config->c_tx_interval);
7676 cfg->g_config.c_tx_interval = config->c_tx_interval;
7777 cfg->g_config.c_ttl = cfg->g_config.c_tx_interval *
7878 cfg->g_config.c_tx_hold;
79 cfg->g_config.c_ttl = (cfg->g_config.c_ttl + 999) / 1000;
7980 }
8081 levent_send_now(cfg);
8182 }
8586 cfg->g_config.c_tx_hold = config->c_tx_hold;
8687 cfg->g_config.c_ttl = cfg->g_config.c_tx_interval *
8788 cfg->g_config.c_tx_hold;
89 cfg->g_config.c_ttl = (cfg->g_config.c_ttl + 999) / 1000;
8890 }
8991 if (CHANGED(c_max_neighbors) && config->c_max_neighbors > 0) {
9092 log_debug("rpc", "client change maximum neighbors to %d",
475475 levent_update_and_send(evutil_socket_t fd, short what, void *arg)
476476 {
477477 struct lldpd *cfg = arg;
478 struct timeval tv = { cfg->g_config.c_tx_interval, 0 };
478 struct timeval tv;
479 long interval_ms = cfg->g_config.c_tx_interval;
480
479481 (void)fd; (void)what;
480482 lldpd_loop(cfg);
481483 if (cfg->g_iface_event != NULL)
482 tv.tv_sec *= 20;
484 interval_ms *= 20;
485 if (interval_ms < 30000)
486 interval_ms = 30000;
487 tv.tv_sec = interval_ms / 1000;
488 tv.tv_usec = (interval_ms % 1000) * 1000;
483489 event_add(cfg->g_main_loop, &tv);
484490 }
485491
821827 (long)tv.tv_sec);
822828 if (event_add(cfg->g_cleanup_timer, &tv) == -1) {
823829 log_warnx("event",
824 "unable to schedula cleanup task");
830 "unable to schedule cleanup task");
825831 event_free(cfg->g_cleanup_timer);
826832 cfg->g_cleanup_timer = NULL;
827833 return;
843849 hardware->h_tx_fast--;
844850
845851 if (hardware->h_tx_fast > 0)
846 tx_interval = hardware->h_cfg->g_config.c_tx_fast_interval;
852 tx_interval = hardware->h_cfg->g_config.c_tx_fast_interval * 1000;
847853 #endif
848854
849 struct timeval tv = { tx_interval, 0 };
855 struct timeval tv;
856 tv.tv_sec = tx_interval / 1000;
857 tv.tv_usec = (tx_interval % 1000) * 1000;
850858 if (event_add(hardware->h_timer, &tv) == -1) {
851859 log_warnx("event", "unable to re-register timer event for port %s",
852860 hardware->h_ifname);
3333
3434 log_debug("interfaces", "initialize ethernet device %s",
3535 hardware->h_ifname);
36 if ((fd = priv_iface_init(hardware->h_ifindex, hardware->h_ifname)) == -1)
36 if ((fd = priv_iface_init(hardware->h_ifindex, hardware->h_ifname, 0)) == -1)
3737 return -1;
3838
3939 /* Allocate receive buffer */
306306 "%s is VLAN %d of %s",
307307 vlan->name, vreq.vlr_tag, lower->name);
308308 vlan->lower = lower;
309 vlan->vlanid = vreq.vlr_tag;
309 bitmap_set(vlan->vlan_bmap, vreq.vlr_tag);
310310 vlan->type |= IFACE_VLAN_T;
311311 }
312312
671671 #ifdef ENABLE_DOT1
672672 interfaces_helper_vlan(cfg, interfaces);
673673 #endif
674 interfaces_helper_mgmt(cfg, addresses);
674 interfaces_helper_mgmt(cfg, addresses, interfaces);
675675 interfaces_helper_chassis(cfg, interfaces);
676676
677677 /* Mac/PHY */
2525 #pragma clang diagnostic push
2626 #pragma clang diagnostic ignored "-Wdocumentation"
2727 #endif
28 #include <netinet/in.h>
2829 #include <linux/if_vlan.h>
2930 #include <linux/if_bonding.h>
3031 #include <linux/if_bridge.h>
4142 #define MAX_BRIDGES 1024
4243
4344 static int
45 only_lldp(struct lldpd *cfg)
46 {
47 int lldp_enabled = 0;
48 int other_enabled = 0;
49 size_t i;
50 for (i=0; cfg->g_protocols[i].mode != 0; i++) {
51 if (cfg->g_protocols[i].mode == LLDPD_MODE_LLDP)
52 lldp_enabled = cfg->g_protocols[i].enabled;
53 else other_enabled = other_enabled || cfg->g_protocols[i].enabled;
54 }
55 return lldp_enabled && !other_enabled;
56
57 }
58
59 static int
4460 iflinux_eth_init(struct lldpd *cfg, struct lldpd_hardware *hardware)
4561 {
4662 int fd;
4763
4864 log_debug("interfaces", "initialize ethernet device %s",
4965 hardware->h_ifname);
50 if ((fd = priv_iface_init(hardware->h_ifindex, hardware->h_ifname)) == -1)
66 if ((fd = priv_iface_init(hardware->h_ifindex, hardware->h_ifname,
67 only_lldp(cfg)?ETH_P_LLDP:ETH_P_ALL)) == -1)
5168 return -1;
5269 hardware->h_sendfd = fd; /* Send */
5370
205222 }
206223
207224 iface->lower = lower;
208 iface->vlanid = ifv.u.VID;
225 bitmap_set(iface->vlan_bmap, ifv.u.VID);
209226 return 1;
210227 }
211228 #endif
659676 struct bond_master *master = hardware->h_data;
660677 int fd;
661678 int un = 1;
679 int proto;
662680
663681 if (!master) return -1;
664682
666684 hardware->h_ifname);
667685
668686 /* First, we get a socket to the raw physical interface */
687 proto = only_lldp(cfg)?ETH_P_LLDP:ETH_P_ALL;
669688 if ((fd = priv_iface_init(hardware->h_ifindex,
670 hardware->h_ifname)) == -1)
689 hardware->h_ifname, proto)) == -1)
671690 return -1;
672691 hardware->h_sendfd = fd;
673692 interfaces_setup_multicast(cfg, hardware->h_ifname, 0);
675694 /* Then, we open a raw interface for the master */
676695 log_debug("interfaces", "enslaved device %s has master %s(%d)",
677696 hardware->h_ifname, master->name, master->index);
678 if ((fd = priv_iface_init(master->index, master->name)) == -1) {
697 if ((fd = priv_iface_init(master->index, master->name, proto)) == -1) {
679698 close(hardware->h_sendfd);
680699 return -1;
681700 }
10191038 #ifdef ENABLE_DOT1
10201039 interfaces_helper_vlan(cfg, interfaces);
10211040 #endif
1022 interfaces_helper_mgmt(cfg, addresses);
1041 interfaces_helper_mgmt(cfg, addresses, interfaces);
10231042 interfaces_helper_chassis(cfg, interfaces);
10241043
10251044 /* Mac/PHY */
163163 interfaces_helper_whitelist(cfg, interfaces);
164164 interfaces_helper_physical(cfg, interfaces,
165165 &bpf_ops, ifbpf_phys_init);
166 interfaces_helper_mgmt(cfg, addresses);
166 interfaces_helper_mgmt(cfg, addresses, interfaces);
167167 interfaces_helper_chassis(cfg, interfaces);
168168
169169 /* Mac/PHY */
210210 lldpd_get_hardware(cfg, lower->name, lower->index);
211211 struct lldpd_port *port;
212212 struct lldpd_vlan *v;
213 char *name = NULL;
214 uint16_t vlan_id;
213215
214216 if (hardware == NULL) {
215217 log_debug("interfaces",
217219 lower->name, vlan->name);
218220 return;
219221 }
220
221 /* Check if the VLAN is already here. */
222222 port = &hardware->h_lport;
223 TAILQ_FOREACH(v, &port->p_vlans, v_entries)
224 if (strncmp(vlan->name, v->v_name, IFNAMSIZ) == 0)
225 return;
226 if ((v = (struct lldpd_vlan *)
227 calloc(1, sizeof(struct lldpd_vlan))) == NULL)
228 return;
229 if ((v->v_name = strdup(vlan->name)) == NULL) {
230 free(v);
231 return;
232 }
233 v->v_vid = vlan->vlanid;
234 log_debug("interfaces", "append VLAN %s for %s",
235 v->v_name,
236 hardware->h_ifname);
237 TAILQ_INSERT_TAIL(&port->p_vlans, v, v_entries);
223
224 for (int i = 0; (i < VLAN_BITMAP_LEN); i++) {
225 if (vlan->vlan_bmap[i] == 0)
226 continue;
227 for (unsigned bit = 0; bit < 32; bit++) {
228 uint32_t mask = 1L << bit;
229 if (!(vlan->vlan_bmap[i] & mask))
230 continue;
231 vlan_id = (i * 32) + bit;
232 if (asprintf(&name, "vlan%d", vlan_id) == -1)
233 return;
234
235 /* Check if the VLAN is already here. */
236 TAILQ_FOREACH(v, &port->p_vlans, v_entries)
237 if (strncmp(name, v->v_name, IFNAMSIZ) == 0) {
238 free(name);
239 return;
240 }
241
242 if ((v = (struct lldpd_vlan *)
243 calloc(1, sizeof(struct lldpd_vlan))) == NULL) {
244 free(name);
245 return;
246 }
247 v->v_name = name;
248 v->v_vid = vlan_id;
249 if (vlan->pvid)
250 port->p_pvid = vlan->pvid;
251 log_debug("interfaces", "append VLAN %s for %s",
252 v->v_name,
253 hardware->h_ifname);
254 TAILQ_INSERT_TAIL(&port->p_vlans, v, v_entries);
255 }
256 }
238257 }
239258
240259 /**
254273 int depth)
255274 {
256275 if (depth > 5) {
257 log_warn("interfaces",
276 log_warnx("interfaces",
258277 "BUG: maximum depth reached when applying VLAN %s (loop?)",
259278 vlan->name);
260279 return;
264283 log_debug("interfaces",
265284 "looking to apply VLAN %s to physical interface behind %s",
266285 vlan->name, upper->name);
286
287 /* Some bridges managed VLAN internally, skip them. */
288 if (upper->type & IFACE_BRIDGE_VLAN_T) {
289 log_debug("interfaces", "VLAN %s ignored for VLAN-aware bridge interface %s",
290 vlan->name, upper->name);
291 return;
292 }
267293
268294 /* Easy: check if we have a lower interface. */
269295 if (upper->lower) {
302328 struct interfaces_device *iface;
303329
304330 TAILQ_FOREACH(iface, interfaces, next) {
305 if (iface->ignore)
306 continue;
307 if (!(iface->type & IFACE_VLAN_T))
331 if (!(iface->type & IFACE_VLAN_T) && bitmap_isempty(iface->vlan_bmap))
308332 continue;
309333
310334 /* We need to find the physical interfaces of this
389413 interfaces_helper_mgmt_for_af(struct lldpd *cfg,
390414 int af,
391415 struct interfaces_address_list *addrs,
416 struct interfaces_device_list *interfaces,
392417 int global, int allnegative)
393418 {
394419 struct interfaces_address *addr;
420 struct interfaces_device *device;
395421 struct lldpd_mgmt *mgmt;
396422 char addrstrbuf[INET6_ADDRSTRLEN];
397423 int found = 0;
437463 continue;
438464 }
439465 if (cfg->g_config.c_mgmt_pattern == NULL ||
440 pattern_match(addrstrbuf, cfg->g_config.c_mgmt_pattern, allnegative)) {
466 /* Match on IP address */
467 pattern_match(addrstrbuf, cfg->g_config.c_mgmt_pattern, allnegative) ||
468 /* Match on interface name */
469 ((device = interfaces_indextointerface(interfaces, addr->index)) &&
470 pattern_match(device->name, cfg->g_config.c_mgmt_pattern, allnegative))) {
441471 mgmt = lldpd_alloc_mgmt(af, &in_addr, in_addr_size,
442472 addr->index);
443473 if (mgmt == NULL) {
462492 to the local chassis). */
463493 void
464494 interfaces_helper_mgmt(struct lldpd *cfg,
465 struct interfaces_address_list *addrs)
495 struct interfaces_address_list *addrs,
496 struct interfaces_device_list *interfaces)
466497 {
467498 int allnegative = 0;
468499 int af;
474505
475506 /* Is the pattern provided an actual IP address? */
476507 if (pattern && strpbrk(pattern, "!,*?") == NULL) {
477 struct in6_addr addr;
508 unsigned char addr[sizeof(struct in6_addr)];
478509 size_t addr_size;
510 struct lldpd_mgmt *mgmt;
511 struct interfaces_address *ifaddr;
512
479513 for (af = LLDPD_AF_UNSPEC + 1;
480514 af != LLDPD_AF_LAST; af++) {
481515 switch (af) {
483517 case LLDPD_AF_IPV6: addr_size = sizeof(struct in6_addr); break;
484518 default: assert(0);
485519 }
486 if (inet_pton(lldpd_af(af), pattern, &addr) == 1)
520 if (inet_pton(lldpd_af(af), pattern, addr) == 1)
487521 break;
488522 }
489 if (af == LLDPD_AF_LAST) {
490 log_debug("interfaces",
491 "interface management pattern is an incorrect IP");
492 } else {
493 struct lldpd_mgmt *mgmt;
494 mgmt = lldpd_alloc_mgmt(af, &addr, addr_size, 0);
523 if (af != LLDPD_AF_LAST) {
524 /* Try to get the index if possible. */
525 TAILQ_FOREACH(ifaddr, addrs, next) {
526 if (ifaddr->address.ss_family != lldpd_af(af))
527 continue;
528 if (LLDPD_AF_IPV4 == af) {
529 struct sockaddr_in *sa_sin;
530 sa_sin = (struct sockaddr_in *)&ifaddr->address;
531 if (0 == memcmp(addr,
532 &(sa_sin->sin_addr),
533 addr_size))
534 break;
535 }
536 else if (LLDPD_AF_IPV6 == af) {
537 if (0 == memcmp(addr,
538 &((struct sockaddr_in6 *)&ifaddr->address)->sin6_addr,
539 addr_size))
540 break;
541 }
542 }
543
544 mgmt = lldpd_alloc_mgmt(af, addr, addr_size, ifaddr ? ifaddr->index : 0);
495545 if (mgmt == NULL) {
496546 log_warn("interfaces", "out of memory error");
497547 return;
498548 }
499549 log_debug("interfaces", "add exact management address %s",
500 pattern);
550 pattern);
501551 TAILQ_INSERT_TAIL(&LOCAL_CHASSIS(cfg)->c_mgmt, mgmt, m_entries);
502 }
503 return;
552 return;
553 }
554 /* else: could be an interface name */
504555 }
505556
506557 /* Is the pattern provided all negative? */
516567
517568 /* Find management addresses */
518569 for (af = LLDPD_AF_UNSPEC + 1; af != LLDPD_AF_LAST; af++) {
519 (void)(interfaces_helper_mgmt_for_af(cfg, af, addrs, 1, allnegative) ||
520 interfaces_helper_mgmt_for_af(cfg, af, addrs, 0, allnegative));
570 (void)(interfaces_helper_mgmt_for_af(cfg, af, addrs, interfaces, 1, allnegative) ||
571 interfaces_helper_mgmt_for_af(cfg, af, addrs, interfaces, 0, allnegative));
521572 }
522573 }
523574
197197 IPv4 and one IPv6 addresses are chosen. Otherwise, many of them can be
198198 selected. If you want to blacklist IPv6 addresses, you can use
199199 .Em !*:* .
200 If an interface name is matched, the first IPv4 address and the first
201 IPv6 address associated to this interface will be chosen.
200202 .It Fl u Ar file
201203 Specify the Unix-domain socket used for communication with
202204 .Xr lldpctl 8 .
661661 free(oport);
662662 }
663663 if (ochassis) {
664 lldpd_move_chassis(ochassis, chassis);
664 if (port->p_ttl == 0) {
665 /* Shutdown LLDPDU is special. We do not want to replace
666 * the chassis. Free the new chassis (which is mostly empty) */
667 log_debug("decode", "received a shutdown LLDPDU");
668 lldpd_chassis_cleanup(chassis, 1);
669 } else {
670 lldpd_move_chassis(ochassis, chassis);
671 }
665672 chassis = ochassis;
666673 } else {
667674 /* Chassis not known, add it */
10001007 selected_port->p_power.allocated,
10011008 hardware->h_lport.p_power.allocated);
10021009 hardware->h_lport.p_power.allocated = selected_port->p_power.allocated;
1010 hardware->h_lport.p_power.allocated_a = selected_port->p_power.allocated_a;
1011 hardware->h_lport.p_power.allocated_b = selected_port->p_power.allocated_b;
10031012 levent_schedule_pdu(hardware);
10041013 }
10051014
18521861 if (lldpcli)
18531862 cfg->g_config.c_paused = 1;
18541863 cfg->g_config.c_receiveonly = receiveonly;
1855 cfg->g_config.c_tx_interval = LLDPD_TX_INTERVAL;
1864 cfg->g_config.c_tx_interval = LLDPD_TX_INTERVAL * 1000;
18561865 cfg->g_config.c_tx_hold = LLDPD_TX_HOLD;
18571866 cfg->g_config.c_ttl = cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold;
1867 cfg->g_config.c_ttl = (cfg->g_config.c_ttl + 999) / 1000;
18581868 cfg->g_config.c_max_neighbors = LLDPD_MAX_NEIGHBORS;
18591869 #ifdef ENABLE_LLDPMED
18601870 cfg->g_config.c_enable_fast_start = enable_fast_start;
200200 int priv_open(char*);
201201 void asroot_open(void);
202202 #endif
203 int priv_iface_init(int, char *);
204 int asroot_iface_init_os(int, char *, int *);
203 int priv_iface_init(int, char *, int);
204 int asroot_iface_init_os(int, char *, int *, int);
205205 int priv_iface_multicast(const char *, const u_int8_t *, int);
206206 int priv_iface_description(const char *, const char *);
207207 int asroot_iface_description_os(const char *, const char *);
261261 (ether dst 00:e0:2b:00:00:00)"
262262 */
263263
264 #define ETH_P_LLDP 0x88cc
264265 #define LLDPD_FILTER_F \
265266 { 0x30, 0, 0, 0x00000000 }, \
266267 { 0x54, 0, 0, 0x00000001 }, \
267268 { 0x15, 0, 16, 0x00000001 }, \
268269 { 0x28, 0, 0, 0x0000000c }, \
269 { 0x15, 0, 6, 0x000088cc }, \
270 { 0x15, 0, 6, ETH_P_LLDP }, \
270271 { 0x20, 0, 0, 0x00000002 }, \
271272 { 0x15, 2, 0, 0xc200000e }, \
272273 { 0x15, 1, 0, 0xc2000003 }, \
296297
297298 /* interfaces.c */
298299 /* An interface cannot be both physical and (bridge or bond or vlan) */
299 #define IFACE_PHYSICAL_T (1 << 0) /* Physical interface */
300 #define IFACE_BRIDGE_T (1 << 1) /* Bridge interface */
301 #define IFACE_BOND_T (1 << 2) /* Bond interface */
302 #define IFACE_VLAN_T (1 << 3) /* VLAN interface */
303 #define IFACE_WIRELESS_T (1 << 4) /* Wireless interface */
300 #define IFACE_PHYSICAL_T (1 << 0) /* Physical interface */
301 #define IFACE_BRIDGE_T (1 << 1) /* Bridge interface */
302 #define IFACE_BOND_T (1 << 2) /* Bond interface */
303 #define IFACE_VLAN_T (1 << 3) /* VLAN interface */
304 #define IFACE_WIRELESS_T (1 << 4) /* Wireless interface */
305 #define IFACE_BRIDGE_VLAN_T (1 << 5) /* Bridge-aware VLAN interface */
306
307 #define MAX_VLAN 4096
308 #define VLAN_BITMAP_LEN (MAX_VLAN / 32)
304309 struct interfaces_device {
305310 TAILQ_ENTRY(interfaces_device) next;
306311 int ignore; /* Ignore this interface */
312317 int flags; /* Flags (IFF_*) */
313318 int mtu; /* MTU */
314319 int type; /* Type (see IFACE_*_T) */
315 int vlanid; /* If a VLAN, what is the VLAN ID? */
320 uint32_t vlan_bmap[VLAN_BITMAP_LEN]; /* If a VLAN, what are the VLAN ID? */
321 int pvid; /* If a VLAN, what is the default VLAN? */
316322 struct interfaces_device *lower; /* Lower interface (for a VLAN for example) */
317323 struct interfaces_device *upper; /* Upper interface (for a bridge or a bond) */
318324
360366 struct lldpd_hardware *,
361367 struct interfaces_device *);
362368 void interfaces_helper_mgmt(struct lldpd *,
363 struct interfaces_address_list *);
369 struct interfaces_address_list *,
370 struct interfaces_device_list *);
364371 #ifdef ENABLE_DOT1
365372 void interfaces_helper_vlan(struct lldpd *,
366373 struct interfaces_device_list *);
381388 #endif
382389
383390 #ifndef HOST_OS_LINUX
391 /* interfaces-bpf.c */
384392 int ifbpf_phys_init(struct lldpd *, struct lldpd_hardware *);
385393 #endif
386394
387395 /* pattern.c */
388396 int pattern_match(char *, char *, int);
397
398 /* bitmap.c */
399 void bitmap_set(uint32_t *bmap, uint16_t vlan_id);
400 int bitmap_isempty(uint32_t *bmap);
401 unsigned int bitmap_numbits(uint32_t *bmap);
389402
390403 struct lldpd {
391404 int g_sock;
2424 #include <net/if_arp.h>
2525 #include <linux/netlink.h>
2626 #include <linux/rtnetlink.h>
27 #include <linux/if_bridge.h>
2728
2829 #define NETLINK_BUFFER 4096
2930
3031 struct netlink_req {
3132 struct nlmsghdr hdr;
32 struct rtgenmsg gen;
33 struct ifinfomsg ifm;
34 /* attribute has to be NLMSG aligned */
35 struct rtattr ext_req __attribute__ ((aligned(NLMSG_ALIGNTO)));
36 __u32 ext_filter_mask;
3337 };
3438
3539 struct lldpd_netlink {
4044 struct interfaces_address_list *addresses;
4145 };
4246
43
4447 /**
4548 * Set netlink socket buffer size.
4649 *
140143 {
141144 struct netlink_req req = {
142145 .hdr = {
143 .nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
146 .nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
144147 .nlmsg_type = type,
145148 .nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP,
146149 .nlmsg_seq = seq,
147150 .nlmsg_pid = getpid() },
148 .gen = { .rtgen_family = family }
151 .ifm = { .ifi_family = family }
149152 };
150153 struct iovec iov = {
151154 .iov_base = &req,
159162 .msg_namelen = sizeof(struct sockaddr_nl)
160163 };
161164
165 if (family == AF_BRIDGE) {
166 unsigned int len = RTA_LENGTH(sizeof(__u32));
167 /* request bridge vlan attributes */
168 req.ext_req.rta_type = IFLA_EXT_MASK;
169 req.ext_req.rta_len = len;
170 req.ext_filter_mask = RTEXT_FILTER_BRVLAN;
171 req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) + RTA_ALIGN(len);
172 iov.iov_len = req.hdr.nlmsg_len;
173 }
174
162175 /* Send netlink message. This is synchronous but we are guaranteed
163176 * to not block. */
164177 log_debug("netlink", "sending netlink message");
192205 {
193206 struct rtattr *link_info_attrs[IFLA_INFO_MAX+1] = {};
194207 char *kind = NULL;
208 uint16_t vlan_id;
195209
196210 netlink_parse_rtattr(link_info_attrs, IFLA_INFO_MAX, rta, len);
197211
225239 RTA_PAYLOAD(link_info_attrs[IFLA_INFO_DATA]));
226240
227241 if (vlan_link_info_data_attrs[IFLA_VLAN_ID]) {
228 iff->vlanid = *(uint16_t *)RTA_DATA(vlan_link_info_data_attrs[IFLA_VLAN_ID]);
242 vlan_id = *(uint16_t *)RTA_DATA(vlan_link_info_data_attrs[IFLA_VLAN_ID]);
243 bitmap_set(iff->vlan_bmap, vlan_id);
229244 log_debug("netlink", "VLAN ID for interface %s is %d",
230 iff->name, iff->vlanid);
245 iff->name, vlan_id);
246 }
247 }
248
249 if (kind && !strcmp(kind, "bridge") && link_info_attrs[IFLA_INFO_DATA]) {
250 struct rtattr *bridge_link_info_data_attrs[IFLA_BR_MAX+1] = {};
251 netlink_parse_rtattr(bridge_link_info_data_attrs, IFLA_BR_MAX,
252 RTA_DATA(link_info_attrs[IFLA_INFO_DATA]),
253 RTA_PAYLOAD(link_info_attrs[IFLA_INFO_DATA]));
254
255 if (bridge_link_info_data_attrs[IFLA_BR_VLAN_FILTERING] &&
256 *(uint8_t *)RTA_DATA(bridge_link_info_data_attrs[IFLA_BR_VLAN_FILTERING]) > 0) {
257 iff->type |= IFACE_BRIDGE_VLAN_T;
231258 }
232259 }
233260
234261 free(kind);
262 }
263
264 /**
265 * Parse a `afspec` attributes.
266 *
267 * @param iff where to put the result
268 * @param rta afspec attribute
269 * @param len length of attributes
270 */
271 static void
272 netlink_parse_afspec(struct interfaces_device *iff, struct rtattr *rta, int len)
273 {
274 while (RTA_OK(rta, len)) {
275 struct bridge_vlan_info *vinfo;
276 switch (rta->rta_type) {
277 case IFLA_BRIDGE_VLAN_INFO:
278 vinfo = RTA_DATA(rta);
279 log_debug("netlink", "found VLAN %d on interface %s",
280 vinfo->vid, iff->name ? iff->name : "(unknown)");
281
282 bitmap_set(iff->vlan_bmap, vinfo->vid);
283 if (vinfo->flags & (BRIDGE_VLAN_INFO_PVID | BRIDGE_VLAN_INFO_UNTAGGED))
284 iff->pvid = vinfo->vid;
285 break;
286 default:
287 log_debug("netlink", "unknown afspec attribute type %d for iface %s",
288 rta->rta_type, iff->name ? iff->name : "(unknown)");
289 break;
290 }
291 rta = RTA_NEXT(rta, len);
292 }
293 /* All enbridged interfaces will have VLAN 1 by default, ignore it */
294 if (iff->vlan_bmap[0] == 2 && (bitmap_numbits(iff->vlan_bmap) == 1)
295 && iff->pvid == 1) {
296 log_debug("netlink", "found only default VLAN 1 on interface %s, removing",
297 iff->name ? iff->name : "(unknown)");
298 iff->vlan_bmap[0] = iff->pvid = 0;
299 }
235300 }
236301
237302 /**
282347 break;
283348 case IFLA_LINK:
284349 /* Index of "lower" interface */
285 iff->lower_idx = *(int*)RTA_DATA(attribute);
286 log_debug("netlink", "attribute IFLA_LINK for %s: %d",
287 iff->name ? iff->name : "(unknown)", iff->lower_idx);
350 if (iff->lower_idx == -1) {
351 iff->lower_idx = *(int*)RTA_DATA(attribute);
352 log_debug("netlink", "attribute IFLA_LINK for %s: %d",
353 iff->name ? iff->name : "(unknown)", iff->lower_idx);
354 } else {
355 log_debug("netlink", "attribute IFLA_LINK for %s: %d (ignored)",
356 iff->name ? iff->name : "(unknown)", iff->lower_idx);
357 }
288358 break;
289359 case IFLA_LINK_NETNSID:
290360 /* Is the lower interface into another namesapce? */
291 iff->lower_idx = -1;
361 iff->lower_idx = -2;
292362 log_debug("netlink", "attribute IFLA_LINK_NETNSID received for %s",
293363 iff->name ? iff->name : "(unknown)");
294364 break;
302372 break;
303373 case IFLA_LINKINFO:
304374 netlink_parse_linkinfo(iff, RTA_DATA(attribute), RTA_PAYLOAD(attribute));
375 break;
376 case IFLA_AF_SPEC:
377 if (ifi->ifi_family != AF_BRIDGE) break;
378 netlink_parse_afspec(iff, RTA_DATA(attribute), RTA_PAYLOAD(attribute));
305379 break;
306380 default:
307381 log_debug("netlink", "unhandled link attribute type %d for iface %s",
320394 * and we don't want to miss it. */
321395 iff->flags &= ~IFF_SLAVE;
322396 }
397 if (iff->lower_idx == -2)
398 iff->lower_idx = -1;
323399
324400 if (ifi->ifi_family == AF_BRIDGE && msg->nlmsg_type == RTM_DELLINK && iff->upper_idx != -1) {
325401 log_debug("netlink", "removal of %s from bridge %d",
326402 iff->name, iff->upper_idx);
327403 msg->nlmsg_type = RTM_NEWLINK;
328404 iff->upper_idx = -1;
329 } else if (ifi->ifi_family != 0) {
330 log_debug("netlink", "skip non-generic message update %d at index %d",
331 ifi->ifi_type, ifi->ifi_index);
332 return -1;
333405 }
334406
335407 log_debug("netlink", "parsed link %d (%s, flags: %d)",
422494 new->mtu = old->mtu;
423495 if (new->type == 0)
424496 new->type = old->type;
425 if (new->vlanid == 0)
426 new->vlanid = old->vlanid;
497
498 if (bitmap_isempty(new->vlan_bmap) && new->type == IFACE_VLAN_T)
499 memcpy((void *)new->vlan_bmap, (void *)old->vlan_bmap,
500 sizeof(uint32_t) * VLAN_BITMAP_LEN);
427501
428502 /* It's not possible for lower link to change */
429503 new->lower_idx = old->lower_idx;
687761 if (iface2->lower_idx == iface1->index) {
688762 iface1->lower = NULL;
689763 log_debug("netlink",
690 "link loop detected between %s and %s",
691 iface1->name, iface2->name);
764 "link loop detected between %s(%d) and %s(%d)",
765 iface1->name,
766 iface1->index,
767 iface2->name,
768 iface2->index);
692769 } else {
693770 log_debug("netlink",
694771 "lower interface for %s is %s",
758835 static int
759836 netlink_initialize(struct lldpd *cfg)
760837 {
838 #ifdef ENABLE_DOT1
839 struct interfaces_device *iff;
840 #endif
841
761842 if (cfg->g_netlink) return 0;
762843
763844 log_debug("netlink", "initialize netlink subsystem");
793874 if (netlink_send(cfg->g_netlink->nl_socket, RTM_GETLINK, AF_PACKET, 2) == -1)
794875 goto end;
795876 netlink_recv(cfg, ifs, NULL);
877 #ifdef ENABLE_DOT1
878 /* If we have a bridge, search for VLAN-aware bridges */
879 TAILQ_FOREACH(iff, ifs, next) {
880 if (iff->type & IFACE_BRIDGE_T) {
881 log_debug("netlink", "interface %s is a bridge, check for VLANs", iff->name);
882 if (netlink_send(cfg->g_netlink->nl_socket, RTM_GETLINK, AF_BRIDGE, 3) == -1)
883 goto end;
884 netlink_recv(cfg, ifs, NULL);
885 break;
886 }
887 }
888 #endif
796889
797890 /* Listen to any future change */
798891 cfg->g_iface_cb = netlink_change_cb;
2626 #include <string.h>
2727
2828 int
29 asroot_iface_init_os(int ifindex, char *name, int *fd)
29 asroot_iface_init_os(int ifindex, char *name, int *fd, int proto)
3030 {
3131 int enable, required, rc;
3232 struct bpf_insn filter[] = { LLDPD_FILTER_F };
114114 }
115115
116116 int
117 asroot_iface_init_os(int ifindex, char *name, int *fd)
117 asroot_iface_init_os(int ifindex, char *name, int *fd, int proto)
118118 {
119119 int rc;
120120 /* Open listening socket to receive/send frames */
121121 if ((*fd = socket(PF_PACKET, SOCK_RAW,
122 htons(ETH_P_ALL))) < 0) {
122 htons(proto))) < 0) {
123123 rc = errno;
124124 return rc;
125125 }
119119
120120
121121 int
122 priv_iface_init(int index, char *iface)
122 priv_iface_init(int index, char *iface, int proto)
123123 {
124124 int rc;
125125 char dev[IFNAMSIZ] = {};
128128 must_write(PRIV_UNPRIVILEGED, &index, sizeof(int));
129129 strlcpy(dev, iface, IFNAMSIZ);
130130 must_write(PRIV_UNPRIVILEGED, dev, IFNAMSIZ);
131 must_write(PRIV_UNPRIVILEGED, &proto, sizeof(int));
131132 priv_wait();
132133 must_read(PRIV_UNPRIVILEGED, &rc, sizeof(int));
133134 if (rc != 0) return -1;
249250 {
250251 int rc = -1, fd = -1;
251252 int ifindex;
253 int proto;
252254 char name[IFNAMSIZ];
253255 must_read(PRIV_PRIVILEGED, &ifindex, sizeof(ifindex));
254256 must_read(PRIV_PRIVILEGED, &name, sizeof(name));
255257 name[sizeof(name) - 1] = '\0';
258 must_read(PRIV_PRIVILEGED, &proto, sizeof(proto))
256259
257260 TRACE(LLDPD_PRIV_INTERFACE_INIT(name));
258 rc = asroot_iface_init_os(ifindex, name, &fd);
261 rc = asroot_iface_init_os(ifindex, name, &fd, proto);
259262 must_write(PRIV_PRIVILEGED, &rc, sizeof(rc));
260263 if (rc == 0 && fd >=0) send_fd(PRIV_PRIVILEGED, fd);
261264 if (fd >= 0) close(fd);
307307 goto malformed;
308308 }
309309 port->p_ttl = cfg?cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold:0;
310 port->p_ttl = (port->p_ttl + 999) / 1000;
310311 chassis->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
311312 chassis->c_id_len = ETHER_ADDR_LEN;
312313 if ((chassis->c_id = (char *)malloc(ETHER_ADDR_LEN)) == NULL) {
293293 /* Power */
294294 if (port->p_power.devicetype) {
295295 if (!(
296 POKE_START_LLDP_TLV(LLDP_TLV_ORG) &&
296 (port->p_power.type_ext != LLDP_DOT3_POWER_8023BT_OFF ?
297 (tlv = pos, POKE_UINT16((LLDP_TLV_ORG << 9) | (0x1d))):
298 POKE_START_LLDP_TLV(LLDP_TLV_ORG)) &&
297299 POKE_BYTES(dot3, sizeof(dot3)) &&
298300 POKE_UINT8(LLDP_TLV_DOT3_POWER) &&
299301 POKE_UINT8((
300 (((2 - port->p_power.devicetype) %(1<< 1))<<0) |
301 (( port->p_power.supported %(1<< 1))<<1) |
302 (( port->p_power.enabled %(1<< 1))<<2) |
303 (( port->p_power.paircontrol %(1<< 1))<<3))) &&
302 (((2 - port->p_power.devicetype) %(1<< 1))<<0) |
303 (( port->p_power.supported %(1<< 1))<<1) |
304 (( port->p_power.enabled %(1<< 1))<<2) |
305 (( port->p_power.paircontrol %(1<< 1))<<3))) &&
304306 POKE_UINT8(port->p_power.pairs) &&
305307 POKE_UINT8(port->p_power.class)))
306308 goto toobig;
307309 /* 802.3at */
308310 if (port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) {
309311 if (!(
310 POKE_UINT8((
311 (((port->p_power.powertype ==
312 POKE_UINT8(((((port->p_power.powertype ==
312313 LLDP_DOT3_POWER_8023AT_TYPE1)?1:0) << 7) |
313 (((port->p_power.devicetype ==
314 (((port->p_power.devicetype ==
314315 LLDP_DOT3_POWER_PSE)?0:1) << 6) |
315 ((port->p_power.source %(1<< 2))<<4) |
316 ((port->p_power.priority %(1<< 2))<<0))) &&
317 POKE_UINT16(port->p_power.requested) &&
318 POKE_UINT16(port->p_power.allocated)))
316 ((port->p_power.source %(1<< 2))<<4) |
317 ((port->p_power.pd_4pid %(1 << 1))<<2) |
318 ((port->p_power.priority %(1<< 2))<<0))) &&
319 POKE_UINT16(port->p_power.requested) &&
320 POKE_UINT16(port->p_power.allocated)))
319321 goto toobig;
320322 }
321 if (!(POKE_END_LLDP_TLV))
322 goto toobig;
323 if (port->p_power.type_ext != LLDP_DOT3_POWER_8023BT_OFF) {
324 if (!(
325 POKE_UINT16(port->p_power.requested_a) &&
326 POKE_UINT16(port->p_power.requested_b) &&
327 POKE_UINT16(port->p_power.allocated_a) &&
328 POKE_UINT16(port->p_power.allocated_b) &&
329 POKE_UINT16((
330 (port->p_power.pse_status << 14) |
331 (port->p_power.pd_status << 12) |
332 (port->p_power.pse_pairs_ext << 10) |
333 (port->p_power.class_a << 7) |
334 (port->p_power.class_b << 4) |
335 (port->p_power.class_ext << 0))) &&
336 POKE_UINT8(
337 /* Adjust by -1 to enable 0 to mean no 802.3bt support */
338 ((port->p_power.type_ext -1) << 1) |
339 (port->p_power.pd_load << 0)) &&
340 POKE_UINT16(port->p_power.pse_max) &&
341 /* Send 0 for autoclass and power down requests */
342 POKE_UINT8(0) &&
343 POKE_UINT16(0) &&
344 POKE_UINT8(0)))
345 goto toobig;
346 }
347 if (!(POKE_END_LLDP_TLV))
348 goto toobig;
323349 }
324350 #endif
325351
491517 return 0;
492518
493519 toobig:
520 log_info("lldp", "Cannot send LLDP packet for %s, Too big message", p_id);
494521 free(packet);
495522 return E2BIG;
496523 }
574601 hardware->h_ifname); \
575602 goto malformed; \
576603 } } while (0)
604 #define CHECK_TLV_MAX_SIZE(x, name) \
605 do { if (tlv_size > (x)) { \
606 log_warnx("lldp", name " TLV too large received on %s", \
607 hardware->h_ifname); \
608 goto malformed; \
609 } } while (0)
577610
578611 int
579612 lldp_decode(struct lldpd *cfg, char *frame, int s,
589622 const char dcbx[] = LLDP_TLV_ORG_DCBX;
590623 unsigned char orgid[3];
591624 int length, gotend = 0, ttl_received = 0;
592 int tlv_size, tlv_type, tlv_subtype;
625 int tlv_size, tlv_type, tlv_subtype, tlv_count = 0;
593626 u_int8_t *pos, *tlv;
594627 char *b;
595628 #ifdef ENABLE_DOT1
666699 hardware->h_ifname);
667700 goto malformed;
668701 }
702 /* Check order for mandatory TLVs */
703 tlv_count++;
704 switch (tlv_type) {
705 case LLDP_TLV_CHASSIS_ID:
706 if (tlv_count != 1) {
707 log_warnx("lldp", "first TLV should be a chassis ID on %s, not %d",
708 hardware->h_ifname, tlv_type);
709 goto malformed;
710 }
711 break;
712 case LLDP_TLV_PORT_ID:
713 if (tlv_count != 2) {
714 log_warnx("lldp", "second TLV should be a port ID on %s, not %d",
715 hardware->h_ifname, tlv_type);
716 goto malformed;
717 }
718 break;
719 case LLDP_TLV_TTL:
720 if (tlv_count != 3) {
721 log_warnx("lldp", "third TLV should be a TTL on %s, not %d",
722 hardware->h_ifname, tlv_type);
723 goto malformed;
724 }
725 break;
726 }
727
669728 switch (tlv_type) {
670729 case LLDP_TLV_END:
671730 if (tlv_size != 0) {
680739 break;
681740 case LLDP_TLV_CHASSIS_ID:
682741 case LLDP_TLV_PORT_ID:
683 CHECK_TLV_SIZE(2, "Port Id");
742 CHECK_TLV_SIZE(2, "Port/Chassis Id");
743 CHECK_TLV_MAX_SIZE(256, "Port/Chassis Id");
684744 tlv_subtype = PEEK_UINT8;
685745 if ((tlv_subtype == 0) || (tlv_subtype > 7)) {
686746 log_warnx("lldp", "unknown subtype for tlv id received on %s",
695755 }
696756 PEEK_BYTES(b, tlv_size - 1);
697757 if (tlv_type == LLDP_TLV_PORT_ID) {
758 if (port->p_id != NULL) {
759 log_warnx("lldp", "Port ID TLV received twice on %s",
760 hardware->h_ifname);
761 free(b);
762 goto malformed;
763 }
698764 port->p_id_subtype = tlv_subtype;
699765 port->p_id = b;
700766 port->p_id_len = tlv_size - 1;
701767 } else {
768 if (chassis->c_id != NULL) {
769 log_warnx("lldp", "Chassis ID TLV received twice on %s",
770 hardware->h_ifname);
771 free(b);
772 goto malformed;
773 }
702774 chassis->c_id_subtype = tlv_subtype;
703775 chassis->c_id = b;
704776 chassis->c_id_len = tlv_size - 1;
705777 }
706778 break;
707779 case LLDP_TLV_TTL:
780 if (ttl_received) {
781 log_warnx("lldp", "TTL TLV received twice on %s",
782 hardware->h_ifname);
783 goto malformed;
784 }
708785 CHECK_TLV_SIZE(2, "TTL");
709786 port->p_ttl = PEEK_UINT16;
710787 ttl_received = 1;
922999 } else
9231000 port->p_power.powertype =
9241001 LLDP_DOT3_POWER_8023AT_OFF;
1002 /* 802.3bt? */
1003 if (tlv_size >= 29) {
1004 port->p_power.requested_a = PEEK_UINT16;
1005 port->p_power.requested_b = PEEK_UINT16;
1006 port->p_power.allocated_a = PEEK_UINT16;
1007 port->p_power.allocated_b = PEEK_UINT16;
1008 port->p_power.pse_status = PEEK_UINT16;
1009 port->p_power.pd_status =
1010 (port->p_power.pse_status & (1<<13 | 1<<12)) >> 12;
1011 port->p_power.pse_pairs_ext =
1012 (port->p_power.pse_status & (1<<11 | 1<<10)) >> 10;
1013 port->p_power.class_a =
1014 (port->p_power.pse_status & (1<<9 | 1<<8 | 1<<7)) >> 7;
1015 port->p_power.class_b =
1016 (port->p_power.pse_status & (1<<6 | 1<<5 | 1<<4)) >> 4;
1017 port->p_power.class_ext =
1018 (port->p_power.pse_status & 0xf);
1019 port->p_power.pse_status =
1020 (port->p_power.pse_status & (1<<15 | 1<<14)) >> 14;
1021 port->p_power.type_ext = PEEK_UINT8;
1022 port->p_power.pd_load =
1023 (port->p_power.type_ext & 0x1);
1024 port->p_power.type_ext =
1025 ((port->p_power.type_ext & (1<<3 | 1<<2 | 1<<1)) + 1);
1026 port->p_power.pse_max = PEEK_UINT16;
1027 } else {
1028 port->p_power.type_ext =
1029 LLDP_DOT3_POWER_8023BT_OFF;
1030 }
9251031 break;
9261032 default:
9271033 /* Unknown Dot3 TLV, ignore it */
11471253 log_warnx("lldp", "unknown tlv (%d) received on %s",
11481254 tlv_type, hardware->h_ifname);
11491255 hardware->h_rx_unrecognized_cnt++;
1150 goto malformed;
1256 break;
11511257 }
11521258 if (pos > tlv + tlv_size) {
11531259 log_warnx("lldp", "BUG: already past TLV!");
366366 TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt, m_entries);
367367 port->p_ttl = cfg?(cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold):
368368 LLDPD_TTL;
369 port->p_ttl = (port->p_ttl + 999) / 1000;
369370
370371 port->p_id_subtype = LLDP_PORTID_SUBTYPE_LOCAL;
371372 if (asprintf(&port->p_id, "%02x-%02x-%02x",
321321 return SET_ERROR(conn, LLDPCTL_ERR_SERIALIZATION);
322322 conn->state = state_send;
323323 if (state_data)
324 conn->state_data = strdup(state_data);
324 strlcpy(conn->state_data, state_data, sizeof(conn->state_data));
325 else
326 conn->state_data[0] = 0;
325327 }
326328 if (conn->state == state_send &&
327 (state_data == NULL || !strcmp(conn->state_data, state_data))) {
329 (state_data == NULL || !strncmp(conn->state_data, state_data, sizeof(conn->state_data)))) {
328330 /* We need to send the currently built message */
329331 rc = lldpctl_send(conn);
330332 if (rc < 0)
332334 conn->state = state_recv;
333335 }
334336 if (conn->state == state_recv &&
335 (state_data == NULL || !strcmp(conn->state_data, state_data))) {
337 (state_data == NULL || !strncmp(conn->state_data, state_data, sizeof(conn->state_data)))) {
336338 /* We need to receive the answer */
337339 while ((rc = ctl_msg_recv_unserialized(&conn->input_buffer,
338340 &conn->input_buffer_len,
346348 return SET_ERROR(conn, LLDPCTL_ERR_SERIALIZATION);
347349 /* rc == 0 */
348350 conn->state = CONN_STATE_IDLE;
349 free(conn->state_data);
350 conn->state_data = NULL;
351 conn->state_data[0] = 0;
351352 return 0;
352353 } else
353354 return SET_ERROR(conn, LLDPCTL_ERR_INVALID_STATE);
4646 #define CONN_STATE_SET_WATCH_SEND 7
4747 #define CONN_STATE_SET_WATCH_RECV 8
4848 #define CONN_STATE_GET_CONFIG_SEND 9
49 #define CONN_STATE_GET_CONFIG_RECV 9
50 #define CONN_STATE_SET_CONFIG_SEND 10
51 #define CONN_STATE_SET_CONFIG_RECV 11
52 #define CONN_STATE_GET_CHASSIS_SEND 12
53 #define CONN_STATE_GET_CHASSIS_RECV 13
54 #define CONN_STATE_GET_DEFAULT_PORT_SEND 14
55 #define CONN_STATE_GET_DEFAULT_PORT_RECV 15
49 #define CONN_STATE_GET_CONFIG_RECV 10
50 #define CONN_STATE_SET_CONFIG_SEND 11
51 #define CONN_STATE_SET_CONFIG_RECV 12
52 #define CONN_STATE_GET_CHASSIS_SEND 13
53 #define CONN_STATE_GET_CHASSIS_RECV 14
54 #define CONN_STATE_GET_DEFAULT_PORT_SEND 15
55 #define CONN_STATE_GET_DEFAULT_PORT_RECV 16
5656 int state; /* Current state */
57 char *state_data; /* Data attached to the state. It is used to
58 * check that we are using the same data as a
59 * previous call until the state machine goes to
60 * CONN_STATE_IDLE. */
61
57 /* Data attached to the state. It is used to check that we are using the
58 * same data as a previous call until the state machine goes to
59 * CONN_STATE_IDLE. */
60 char state_data[IFNAMSIZ + 64];
6261 /* Error handling */
6362 lldpctl_error_t error; /* Last error */
6463
8079 void *to_send, struct marshal_info *mi_send,
8180 void **to_recv, struct marshal_info *mi_recv);
8281
83 /* error.c */
82 /* errors.c */
8483 #define SET_ERROR(conn, x) ((conn)->error = x)
8584 #define RESET_ERROR(conn) SET_ERROR((conn), LLDPCTL_NO_ERROR)
8685
220220 case lldpctl_k_config_paused:
221221 return c->config->c_paused;
222222 case lldpctl_k_config_tx_interval:
223 return c->config->c_tx_interval;
223 return (c->config->c_tx_interval+999)/1000; /* s units */
224 case lldpctl_k_config_tx_interval_ms:
225 return c->config->c_tx_interval; /* ms units */
224226 case lldpctl_k_config_receiveonly:
225227 return c->config->c_receiveonly;
226228 case lldpctl_k_config_advertise_version:
266268 config.c_paused = c->config->c_paused = value;
267269 break;
268270 case lldpctl_k_config_tx_interval:
271 config.c_tx_interval = value * 1000;
272 if (value > 0) c->config->c_tx_interval = value * 1000;
273 break;
274 case lldpctl_k_config_tx_interval_ms:
269275 config.c_tx_interval = value;
270276 if (value > 0) c->config->c_tx_interval = value;
271277 break;
4747 static struct atom_map port_dot3_power_pairs_map = {
4848 .key = lldpctl_k_dot3_power_pairs,
4949 .map = {
50 { 0, "unknown" },
5051 { LLDP_DOT3_POWERPAIRS_SIGNAL, "signal" },
5152 { LLDP_DOT3_POWERPAIRS_SPARE, "spare" },
5253 { 0, NULL }
7576 { 0, NULL },
7677 },
7778 };
79
80 static struct atom_map port_dot3_power_pd_4pid_map = {
81 .key = lldpctl_k_dot3_power_pd_4pid,
82 .map = {
83 { 0, "PD does not support powering both modes" },
84 { 1, "PD supports powering both modes" },
85 },
86 };
87
88 static struct atom_map port_dot3_power_pse_status_map = {
89 .key = lldpctl_k_dot3_power_pse_status,
90 .map = {
91 { 0, "Unknown" },
92 { 1, "2-pair powering" },
93 { 2, "4-pair powering dual-signature PD" },
94 { 3, "4-pair powering single-signature PD" },
95 },
96 };
97
98 static struct atom_map port_dot3_power_pd_status_map = {
99 .key = lldpctl_k_dot3_power_pd_status,
100 .map = {
101 { 0, "Unknown" },
102 { 1, "2-pair powered PD" },
103 { 2, "4-pair powered dual-signature PD" },
104 { 3, "4-pair powered single-signature PD" },
105 },
106 };
107
108 static struct atom_map port_dot3_power_pse_pairs_ext_map = {
109 .key = lldpctl_k_dot3_power_pse_pairs_ext,
110 .map = {
111 { 0, "Unknown" },
112 { 1, "Alternative A" },
113 { 2, "Alternative B" },
114 { 3, "Both alternatives" },
115 },
116 };
117
118 static struct atom_map port_dot3_power_class_a_map = {
119 .key = lldpctl_k_dot3_power_class_a,
120 .map = {
121 { 0, "Unknown" },
122 { 1, "Class 1" },
123 { 2, "Class 2" },
124 { 3, "Class 3" },
125 { 4, "Class 4" },
126 { 5, "Class 5" },
127 { 6, "Unknown" },
128 { 7, "Single-signature PD or 2-pair only PSE" },
129 },
130 };
131
132 static struct atom_map port_dot3_power_class_b_map = {
133 .key = lldpctl_k_dot3_power_class_b,
134 .map = {
135 { 0, "Unknown" },
136 { 1, "Class 1" },
137 { 2, "Class 2" },
138 { 3, "Class 3" },
139 { 4, "Class 4" },
140 { 5, "Class 5" },
141 { 6, "Unknown" },
142 { 7, "Single-signature PD or 2-pair only PSE" },
143 },
144 };
145
146 static struct atom_map port_dot3_power_class_ext_map = {
147 .key = lldpctl_k_dot3_power_class_ext,
148 .map = {
149 { 0, "Unknown" },
150 { 1, "Class 1" },
151 { 2, "Class 2" },
152 { 3, "Class 3" },
153 { 4, "Class 4" },
154 { 5, "Class 5" },
155 { 6, "Class 6" },
156 { 7, "Class 7" },
157 { 8, "Class 8" },
158 { 9, "Unknown" },
159 { 10, "Unknown" },
160 { 11, "Unknown" },
161 { 12, "Unknown" },
162 { 13, "Unknown" },
163 { 14, "Unknown" },
164 { 15, "Dual-signature PD" },
165 },
166 };
167
168 static struct atom_map port_dot3_power_type_ext_map = {
169 .key = lldpctl_k_dot3_power_type_ext,
170 .map = {
171 { LLDP_DOT3_POWER_8023BT_OFF, "802.3bt off" },
172 { 1, "Type 3 PSE" },
173 { 2, "Type 4 PSE" },
174 { 3, "Type 3 single-signature PD" },
175 { 4, "Type 3 dual-signature PD" },
176 { 5, "Type 4 single-signature PD" },
177 { 6, "Type 4 dual-signature PD" },
178 { 7, "Unknown" },
179 { 8, "Unknown" },
180 },
181 };
182
183 static struct atom_map port_dot3_power_pd_load_map = {
184 .key = lldpctl_k_dot3_power_pd_load,
185 .map = {
186 { 0, "PD is single- or dual-signature and power is not "
187 "electrically isolated" },
188 { 1, "PD is dual-signature and power is electrically "
189 "isolated" },
190 },
191 };
192
78193
79194 ATOM_MAP_REGISTER(port_dot3_power_pairs_map, 4);
80195 ATOM_MAP_REGISTER(port_dot3_power_class_map, 5);
124239 case lldpctl_k_dot3_power_priority:
125240 return map_lookup(port_dot3_power_priority_map.map,
126241 port->p_power.priority);
242 case lldpctl_k_dot3_power_pd_4pid:
243 return map_lookup(port_dot3_power_pd_4pid_map.map,
244 port->p_power.pd_4pid);
245 case lldpctl_k_dot3_power_pse_status:
246 return map_lookup(port_dot3_power_pse_status_map.map,
247 port->p_power.pse_status);
248 case lldpctl_k_dot3_power_pd_status:
249 return map_lookup(port_dot3_power_pd_status_map.map,
250 port->p_power.pd_status);
251 case lldpctl_k_dot3_power_pse_pairs_ext:
252 return map_lookup(port_dot3_power_pse_pairs_ext_map.map,
253 port->p_power.pse_pairs_ext);
254 case lldpctl_k_dot3_power_class_a:
255 return map_lookup(port_dot3_power_class_a_map.map,
256 port->p_power.class_a);
257 case lldpctl_k_dot3_power_class_b:
258 return map_lookup(port_dot3_power_class_b_map.map,
259 port->p_power.class_b);
260 case lldpctl_k_dot3_power_class_ext:
261 return map_lookup(port_dot3_power_class_ext_map.map,
262 port->p_power.class_ext);
263 case lldpctl_k_dot3_power_type_ext:
264 return map_lookup(port_dot3_power_type_ext_map.map,
265 port->p_power.type_ext);
266 case lldpctl_k_dot3_power_pd_load:
267 return map_lookup(port_dot3_power_pd_load_map.map,
268 port->p_power.pd_load);
127269 default:
128270 SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST);
129271 return NULL;
161303 return port->p_power.requested * 100;
162304 case lldpctl_k_dot3_power_allocated:
163305 return port->p_power.allocated * 100;
306 /* 802.3bt additions */
307 case lldpctl_k_dot3_power_pd_4pid:
308 return port->p_power.pd_4pid;
309 case lldpctl_k_dot3_power_requested_a:
310 return port->p_power.requested_a * 100;
311 case lldpctl_k_dot3_power_requested_b:
312 return port->p_power.requested_b * 100;
313 case lldpctl_k_dot3_power_allocated_a:
314 return port->p_power.allocated_a * 100;
315 case lldpctl_k_dot3_power_allocated_b:
316 return port->p_power.allocated_b * 100;
317 case lldpctl_k_dot3_power_pse_status:
318 return port->p_power.pse_status;
319 case lldpctl_k_dot3_power_pd_status:
320 return port->p_power.pd_status;
321 case lldpctl_k_dot3_power_pse_pairs_ext:
322 return port->p_power.pse_pairs_ext;
323 case lldpctl_k_dot3_power_class_a:
324 return port->p_power.class_a;
325 case lldpctl_k_dot3_power_class_b:
326 return port->p_power.class_b;
327 case lldpctl_k_dot3_power_class_ext:
328 return port->p_power.class_ext;
329 case lldpctl_k_dot3_power_type_ext:
330 return port->p_power.type_ext;
331 case lldpctl_k_dot3_power_pd_load:
332 return port->p_power.pd_load;
333 case lldpctl_k_dot3_power_pse_max:
334 return port->p_power.pse_max * 100;
164335 default:
165336 return SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST);
166337 }
216387 }
217388 case lldpctl_k_dot3_power_pairs:
218389 switch (value) {
390 case 0:
219391 case 1:
220392 case 2:
221393 port->p_power.pairs = value;
258430 case lldpctl_k_dot3_power_requested:
259431 if (value < 0) goto bad;
260432 port->p_power.requested = value / 100;
433 return atom;
434 /* 802.3bt additions */
435 case lldpctl_k_dot3_power_pd_4pid:
436 port->p_power.pd_4pid = value;
437 return atom;
438 case lldpctl_k_dot3_power_requested_a:
439 port->p_power.requested_a = value / 100;
440 return atom;
441 case lldpctl_k_dot3_power_requested_b:
442 port->p_power.requested_b = value / 100;
443 return atom;
444 case lldpctl_k_dot3_power_allocated_a:
445 port->p_power.allocated_a = value / 100;
446 return atom;
447 case lldpctl_k_dot3_power_allocated_b:
448 port->p_power.allocated_b = value / 100;
449 return atom;
450 case lldpctl_k_dot3_power_pse_status:
451 port->p_power.pse_status = value;
452 return atom;
453 case lldpctl_k_dot3_power_pd_status:
454 port->p_power.pd_status = value;
455 return atom;
456 case lldpctl_k_dot3_power_pse_pairs_ext:
457 port->p_power.pse_pairs_ext = value;
458 return atom;
459 case lldpctl_k_dot3_power_class_a:
460 port->p_power.class_a = value;
461 return atom;
462 case lldpctl_k_dot3_power_class_b:
463 port->p_power.class_b = value;
464 return atom;
465 case lldpctl_k_dot3_power_class_ext:
466 port->p_power.class_ext = value;
467 return atom;
468 case lldpctl_k_dot3_power_type_ext:
469 port->p_power.type_ext = value;
470 return atom;
471 case lldpctl_k_dot3_power_pd_load:
472 port->p_power.pd_load = value;
473 return atom;
474 case lldpctl_k_dot3_power_pse_max:
475 port->p_power.pse_max = value / 100;
261476 return atom;
262477 default:
263478 SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST);
8686 lldpctl_atom_dec_ref(mgmt->parent);
8787 }
8888
89 static long int
90 _lldpctl_atom_get_int_mgmt(lldpctl_atom_t *atom, lldpctl_key_t key)
91 {
92 struct _lldpctl_atom_mgmt_t *m =
93 (struct _lldpctl_atom_mgmt_t *)atom;
94
95 /* Local and remote port */
96 switch (key) {
97 case lldpctl_k_mgmt_iface_index:
98 return m->mgmt->m_iface;
99 default:
100 return SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST);
101 }
102 }
103
89104 static const char*
90105 _lldpctl_atom_get_str_mgmt(lldpctl_atom_t *atom, lldpctl_key_t key)
91106 {
135150 { atom_mgmt, sizeof(struct _lldpctl_atom_mgmt_t),
136151 .init = _lldpctl_atom_new_mgmt,
137152 .free = _lldpctl_atom_free_mgmt,
153 .get_int = _lldpctl_atom_get_int_mgmt,
138154 .get_str = _lldpctl_atom_get_str_mgmt };
139155
140156 ATOM_BUILDER_REGISTER(mgmts_list, 6);
328328 struct lldpd_hardware *hardware = p->hardware;
329329 struct lldpd_port_set set = {};
330330 int rc;
331 char *canary;
331 char *canary = NULL;
332332
333333 #ifdef ENABLE_DOT3
334334 struct _lldpctl_atom_dot3_power_t *dpow;
113113 }
114114 if (!send && !recv) {
115115 if ((data = malloc(sizeof(struct lldpctl_conn_sync_t))) == NULL) {
116 free(conn->ctlname);
116117 free(conn);
117118 return NULL;
118119 }
230230 * translate this error code.
231231 *
232232 * When a function returns an integer, it may return a negative value. It
233 * usually means this is an error but some functions may return a legetimate
233 * usually means this is an error but some functions may return a legitimate
234234 * negative value (for example @ref lldpctl_atom_get_int()). When there is a
235235 * doubt, @ref lldpctl_last_error() should be checked.
236236 *
641641 * written. An atom marked with (IS) can be retrieved as an integer and features
642642 * an appropriate representation as a string (usually, the name of a constant)
643643 * which is more meaningful than just the integer. An atom marked as (I) can be
644 * retrieved and as a string. In the later case, this is just a string
645 * representation of the integer. An atom marked with (AL) can be retrieved as
646 * an atom only and can be iterated over. This is usually a list of things. An
647 * atom marked (I,W) can be read as an integer or a string and can be written as
648 * an integer. The change would not be commited until the atom is written to the
649 * nearest atom supporting (A,WO) operation (eventually with an indirection, i.e
650 * first write to a (A,W), then to a (A,WO)).
644 * retrieved as an integer and as a string. In the later case, this is just a
645 * string representation of the integer. An atom marked with (AL) can be
646 * retrieved as an atom only and can be iterated over. This is usually a list of
647 * things. An atom marked (I,W) can be read as an integer or a string and can be
648 * written as an integer. The change would not be commited until the atom is
649 * written to the nearest atom supporting (A,WO) operation (eventually with an
650 * indirection, i.e first write to a (A,W), then to a (A,WO)).
651651 */
652652 typedef enum {
653653 lldpctl_k_config_tx_interval, /**< `(I,WO)` Transmit interval. When set to -1, it is meant to transmit now. */
669669 lldpctl_k_config_chassis_mgmt_advertise, /**< `(I,WO)` Enable or disable management addresses advertisement */
670670 lldpctl_k_config_cid_string, /**< `(S,WON)` User defined string for the chassis ID */
671671 lldpctl_k_config_perm_iface_pattern, /**< `(S,WON)` Pattern of permanent interfaces */
672 lldpctl_k_config_tx_interval_ms, /**< `(I,WO)` Transmit interval in milliseconds. Set to -1 to transmit now. */
672673
673674 lldpctl_k_interface_name = 1000, /**< `(S)` The interface name. */
674675
710711 lldpctl_k_dot3_power_allocated, /**< `(I,W)` 802.3AT power allocated */
711712 lldpctl_k_dot3_power_requested, /**< `(I,W)` 802.3AT power requested */
712713
714 /* 802.3bt additions */
715 lldpctl_k_dot3_power_pd_4pid, /**< `(IS,W)` 802.3BT both modes supported? */
716 lldpctl_k_dot3_power_requested_a, /**< `(I,W)` 802.3BT power value requested for A */
717 lldpctl_k_dot3_power_requested_b, /**< `(I,W)` 802.3BT power value requested for B */
718 lldpctl_k_dot3_power_allocated_a, /**< `(I,W)` 802.3BT power value allocated for A */
719 lldpctl_k_dot3_power_allocated_b, /**< `(I,W)` 802.3BT power value allocated for B */
720 lldpctl_k_dot3_power_pse_status, /**< `(IS,W)` 802.3BT PSE powering status */
721 lldpctl_k_dot3_power_pd_status, /**< `(IS,W)` 802.3BT PD powering status */
722 lldpctl_k_dot3_power_pse_pairs_ext, /**< `(IS,W)` 802.3BT PSE power pairs */
723 lldpctl_k_dot3_power_class_a, /**< `(IS,W)` 802.3BT power class for A */
724 lldpctl_k_dot3_power_class_b, /**< `(IS,W)` 802.3BT power class for B */
725 lldpctl_k_dot3_power_class_ext, /**< `(IS,W)` 802.3BT power class */
726 lldpctl_k_dot3_power_type_ext, /**< `(IS,W)` 802.3BT power type */
727 lldpctl_k_dot3_power_pd_load, /**< `(IS,W)` 802.3BT dualsig isolated? */
728 lldpctl_k_dot3_power_pse_max, /**< `(I,W)` 802.3BT maximum available power */
729
713730 lldpctl_k_port_vlan_pvid = 1500, /**< `(I)` Primary VLAN ID */
714731 lldpctl_k_port_vlans, /**< `(AL)` List of VLAN */
715732 lldpctl_k_vlan_id, /**< `(I)` VLAN ID */
777794 lldpctl_k_med_power_val, /**< `(I,W)` LLDP MED power value */
778795
779796 lldpctl_k_mgmt_ip = 3000, /**< `(S)` IP address */
797 lldpctl_k_mgmt_iface_index = 30001, /**< `(I)` Interface index */
780798
781799 lldpctl_k_tx_cnt = 4000, /**< `(I)` tx cnt. Only works for a local port. */
782800 lldpctl_k_rx_cnt, /**< `(I)` rx cnt. Only works for a local port. */
139139 #define LLDP_DOT3_POWER_8023AT_TYPE1 1
140140 #define LLDP_DOT3_POWER_8023AT_TYPE2 2
141141
142 /* 802.3bt additions */
143 #define LLDP_DOT3_POWER_8023BT_OFF 0
144 #define LLDP_DOT3_POWER_8023BT_TYPE3 1
145 #define LLDP_DOT3_POWER_8023BT_TYPE4 2
146
142147 /* Dot3 power source */
143148 #define LLDP_DOT3_POWER_SOURCE_UNKNOWN 0
144149 #define LLDP_DOT3_POWER_SOURCE_PRIMARY 1
7272 free(vlan);
7373 }
7474 TAILQ_INIT(&port->p_vlans);
75 port->p_pvid = 0;
7576 }
7677
7778 void
124124 u_int8_t priority;
125125 u_int16_t requested;
126126 u_int16_t allocated;
127
128 /* For 802.3BT */
129 u_int8_t pd_4pid;
130 u_int16_t requested_a;
131 u_int16_t requested_b;
132 u_int16_t allocated_a;
133 u_int16_t allocated_b;
134 u_int16_t pse_status;
135 u_int8_t pd_status;
136 u_int8_t pse_pairs_ext;
137 u_int8_t class_a;
138 u_int8_t class_b;
139 u_int8_t class_ext;
140 u_int8_t type_ext;
141 u_int8_t pd_load;
142 u_int16_t pse_max;
127143 };
128144 MARSHAL(lldpd_dot3_power);
129145 #endif
243259 struct lldpd_frame *p_lastframe; /* Frame received during last update */
244260 u_int8_t p_protocol; /* Protocol used to get this port */
245261 u_int8_t p_hidden_in:1; /* Considered as hidden for reception */
246 u_int8_t p_hidden_out:2; /* Considered as hidden for emission */
247 u_int8_t p_disable_rx:3; /* Should RX be disabled for this port? */
248 u_int8_t p_disable_tx:4; /* Should TX be disabled for this port? */
262 u_int8_t p_hidden_out:1; /* Considered as hidden for emission */
263 u_int8_t p_disable_rx:1; /* Should RX be disabled for this port? */
264 u_int8_t p_disable_tx:1; /* Should TX be disabled for this port? */
249265 /* Important: all fields that should be ignored to check if a port has
250266 * been changed should be before this mark. */
251267 #define LLDPD_PORT_START_MARKER (offsetof(struct lldpd_port, _p_hardware_flags))
371387
372388 struct lldpd_config {
373389 int c_paused; /* lldpd is paused */
374 int c_tx_interval; /* Transmit interval */
390 int c_tx_interval; /* Transmit interval (in ms) */
375391 int c_ttl; /* TTL */
376392 int c_smart; /* Bitmask for smart configuration (see SMART_*) */
377393 int c_receiveonly; /* Receive only mode */
114114 case LOG_WARNING: return "\033[1;33m[WARN";
115115 case LOG_NOTICE: return "\033[1;34m[NOTI";
116116 case LOG_INFO: return "\033[1;34m[INFO";
117 case LOG_DEBUG: return "\033[1;30m[ DBG";
117 case LOG_DEBUG: return "\033[36m[ DBG";
118118 }
119119 break;
120120 default:
33
44 if HAVE_CHECK
55
6 TESTS = check_marshal check_pattern check_lldp check_cdp check_sonmp check_edp check_fixedpoint
6 TESTS = check_marshal check_pattern check_bitmap check_fixedpoint \
7 check_lldp check_cdp check_sonmp check_edp
78 AM_CFLAGS += @check_CFLAGS@
89 LDADD = $(top_builddir)/src/daemon/liblldpd.la @check_LIBS@ @libevent_LDFLAGS@
910
1213 check-compat.h
1314
1415 check_pattern_SOURCES = check_pattern.c \
16 $(top_srcdir)/src/daemon/lldpd.h
17
18 check_bitmap_SOURCES = check_bitmap.c \
1519 $(top_srcdir)/src/daemon/lldpd.h
1620
1721 check_lldp_SOURCES = check_lldp.c \
8787 build_triplet = @build@
8888 host_triplet = @host@
8989 @HAVE_CHECK_TRUE@TESTS = check_marshal$(EXEEXT) check_pattern$(EXEEXT) \
90 @HAVE_CHECK_TRUE@ check_lldp$(EXEEXT) check_cdp$(EXEEXT) \
91 @HAVE_CHECK_TRUE@ check_sonmp$(EXEEXT) check_edp$(EXEEXT) \
92 @HAVE_CHECK_TRUE@ check_fixedpoint$(EXEEXT) $(am__EXEEXT_1)
90 @HAVE_CHECK_TRUE@ check_bitmap$(EXEEXT) \
91 @HAVE_CHECK_TRUE@ check_fixedpoint$(EXEEXT) check_lldp$(EXEEXT) \
92 @HAVE_CHECK_TRUE@ check_cdp$(EXEEXT) check_sonmp$(EXEEXT) \
93 @HAVE_CHECK_TRUE@ check_edp$(EXEEXT) $(am__EXEEXT_1)
9394 @HAVE_CHECK_TRUE@am__append_1 = @check_CFLAGS@
9495 @HAVE_CHECK_TRUE@@USE_SNMP_TRUE@am__append_2 = check_snmp
9596 @HAVE_CHECK_TRUE@@USE_SNMP_TRUE@am__append_3 = @NETSNMP_LIBS@
122123 CONFIG_CLEAN_VPATH_FILES =
123124 @HAVE_CHECK_TRUE@@USE_SNMP_TRUE@am__EXEEXT_1 = check_snmp$(EXEEXT)
124125 @HAVE_CHECK_TRUE@am__EXEEXT_2 = check_marshal$(EXEEXT) \
125 @HAVE_CHECK_TRUE@ check_pattern$(EXEEXT) check_lldp$(EXEEXT) \
126 @HAVE_CHECK_TRUE@ check_pattern$(EXEEXT) check_bitmap$(EXEEXT) \
127 @HAVE_CHECK_TRUE@ check_fixedpoint$(EXEEXT) check_lldp$(EXEEXT) \
126128 @HAVE_CHECK_TRUE@ check_cdp$(EXEEXT) check_sonmp$(EXEEXT) \
127 @HAVE_CHECK_TRUE@ check_edp$(EXEEXT) check_fixedpoint$(EXEEXT) \
128 @HAVE_CHECK_TRUE@ $(am__EXEEXT_1)
129 @HAVE_CHECK_TRUE@ check_edp$(EXEEXT) $(am__EXEEXT_1)
130 am__check_bitmap_SOURCES_DIST = check_bitmap.c \
131 $(top_srcdir)/src/daemon/lldpd.h
132 @HAVE_CHECK_TRUE@am_check_bitmap_OBJECTS = check_bitmap.$(OBJEXT)
133 check_bitmap_OBJECTS = $(am_check_bitmap_OBJECTS)
134 check_bitmap_LDADD = $(LDADD)
135 am__DEPENDENCIES_1 =
136 @HAVE_CHECK_TRUE@check_bitmap_DEPENDENCIES = \
137 @HAVE_CHECK_TRUE@ $(top_builddir)/src/daemon/liblldpd.la \
138 @HAVE_CHECK_TRUE@ $(am__DEPENDENCIES_1)
139 AM_V_lt = $(am__v_lt_@AM_V@)
140 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
141 am__v_lt_0 = --silent
142 am__v_lt_1 =
129143 am__check_cdp_SOURCES_DIST = check_cdp.c \
130144 $(top_srcdir)/src/daemon/lldpd.h common.h common.c \
131145 check-compat.h
133147 @HAVE_CHECK_TRUE@ common.$(OBJEXT)
134148 check_cdp_OBJECTS = $(am_check_cdp_OBJECTS)
135149 check_cdp_LDADD = $(LDADD)
136 am__DEPENDENCIES_1 =
137150 @HAVE_CHECK_TRUE@check_cdp_DEPENDENCIES = \
138151 @HAVE_CHECK_TRUE@ $(top_builddir)/src/daemon/liblldpd.la \
139152 @HAVE_CHECK_TRUE@ $(am__DEPENDENCIES_1)
140 AM_V_lt = $(am__v_lt_@AM_V@)
141 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
142 am__v_lt_0 = --silent
143 am__v_lt_1 =
144153 am__check_edp_SOURCES_DIST = check_edp.c \
145154 $(top_srcdir)/src/daemon/lldpd.h common.h common.c \
146155 check-compat.h
230239 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
231240 depcomp = $(SHELL) $(top_srcdir)/depcomp
232241 am__maybe_remake_depfiles = depfiles
233 am__depfiles_remade = ./$(DEPDIR)/check_cdp.Po \
234 ./$(DEPDIR)/check_edp.Po ./$(DEPDIR)/check_fixedpoint.Po \
235 ./$(DEPDIR)/check_lldp.Po ./$(DEPDIR)/check_marshal.Po \
236 ./$(DEPDIR)/check_pattern.Po ./$(DEPDIR)/check_snmp.Po \
237 ./$(DEPDIR)/check_sonmp.Po ./$(DEPDIR)/common.Po \
238 ./$(DEPDIR)/decode.Po
242 am__depfiles_remade = ./$(DEPDIR)/check_bitmap.Po \
243 ./$(DEPDIR)/check_cdp.Po ./$(DEPDIR)/check_edp.Po \
244 ./$(DEPDIR)/check_fixedpoint.Po ./$(DEPDIR)/check_lldp.Po \
245 ./$(DEPDIR)/check_marshal.Po ./$(DEPDIR)/check_pattern.Po \
246 ./$(DEPDIR)/check_snmp.Po ./$(DEPDIR)/check_sonmp.Po \
247 ./$(DEPDIR)/common.Po ./$(DEPDIR)/decode.Po
239248 am__mv = mv -f
240249 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
241250 $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
255264 am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
256265 am__v_CCLD_0 = @echo " CCLD " $@;
257266 am__v_CCLD_1 =
258 SOURCES = $(check_cdp_SOURCES) $(check_edp_SOURCES) \
259 $(check_fixedpoint_SOURCES) $(check_lldp_SOURCES) \
260 $(check_marshal_SOURCES) $(check_pattern_SOURCES) \
261 $(check_snmp_SOURCES) $(check_sonmp_SOURCES) $(decode_SOURCES)
262 DIST_SOURCES = $(am__check_cdp_SOURCES_DIST) \
263 $(am__check_edp_SOURCES_DIST) \
267 SOURCES = $(check_bitmap_SOURCES) $(check_cdp_SOURCES) \
268 $(check_edp_SOURCES) $(check_fixedpoint_SOURCES) \
269 $(check_lldp_SOURCES) $(check_marshal_SOURCES) \
270 $(check_pattern_SOURCES) $(check_snmp_SOURCES) \
271 $(check_sonmp_SOURCES) $(decode_SOURCES)
272 DIST_SOURCES = $(am__check_bitmap_SOURCES_DIST) \
273 $(am__check_cdp_SOURCES_DIST) $(am__check_edp_SOURCES_DIST) \
264274 $(am__check_fixedpoint_SOURCES_DIST) \
265275 $(am__check_lldp_SOURCES_DIST) \
266276 $(am__check_marshal_SOURCES_DIST) \
696706 @HAVE_CHECK_TRUE@check_pattern_SOURCES = check_pattern.c \
697707 @HAVE_CHECK_TRUE@ $(top_srcdir)/src/daemon/lldpd.h
698708
709 @HAVE_CHECK_TRUE@check_bitmap_SOURCES = check_bitmap.c \
710 @HAVE_CHECK_TRUE@ $(top_srcdir)/src/daemon/lldpd.h
711
699712 @HAVE_CHECK_TRUE@check_lldp_SOURCES = check_lldp.c \
700713 @HAVE_CHECK_TRUE@ $(top_srcdir)/src/daemon/lldpd.h \
701714 @HAVE_CHECK_TRUE@ common.h common.c check-compat.h
766779 echo " rm -f" $$list; \
767780 rm -f $$list
768781
782 check_bitmap$(EXEEXT): $(check_bitmap_OBJECTS) $(check_bitmap_DEPENDENCIES) $(EXTRA_check_bitmap_DEPENDENCIES)
783 @rm -f check_bitmap$(EXEEXT)
784 $(AM_V_CCLD)$(LINK) $(check_bitmap_OBJECTS) $(check_bitmap_LDADD) $(LIBS)
785
769786 check_cdp$(EXEEXT): $(check_cdp_OBJECTS) $(check_cdp_DEPENDENCIES) $(EXTRA_check_cdp_DEPENDENCIES)
770787 @rm -f check_cdp$(EXEEXT)
771788 $(AM_V_CCLD)$(LINK) $(check_cdp_OBJECTS) $(check_cdp_LDADD) $(LIBS)
808825 distclean-compile:
809826 -rm -f *.tab.c
810827
828 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_bitmap.Po@am__quote@ # am--include-marker
811829 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_cdp.Po@am__quote@ # am--include-marker
812830 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_edp.Po@am__quote@ # am--include-marker
813831 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_fixedpoint.Po@am__quote@ # am--include-marker
10621080 --log-file $$b.log --trs-file $$b.trs \
10631081 $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
10641082 "$$tst" $(AM_TESTS_FD_REDIRECT)
1083 check_bitmap.log: check_bitmap$(EXEEXT)
1084 @p='check_bitmap$(EXEEXT)'; \
1085 b='check_bitmap'; \
1086 $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
1087 --log-file $$b.log --trs-file $$b.trs \
1088 $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
1089 "$$tst" $(AM_TESTS_FD_REDIRECT)
1090 check_fixedpoint.log: check_fixedpoint$(EXEEXT)
1091 @p='check_fixedpoint$(EXEEXT)'; \
1092 b='check_fixedpoint'; \
1093 $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
1094 --log-file $$b.log --trs-file $$b.trs \
1095 $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
1096 "$$tst" $(AM_TESTS_FD_REDIRECT)
10651097 check_lldp.log: check_lldp$(EXEEXT)
10661098 @p='check_lldp$(EXEEXT)'; \
10671099 b='check_lldp'; \
10861118 check_edp.log: check_edp$(EXEEXT)
10871119 @p='check_edp$(EXEEXT)'; \
10881120 b='check_edp'; \
1089 $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
1090 --log-file $$b.log --trs-file $$b.trs \
1091 $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
1092 "$$tst" $(AM_TESTS_FD_REDIRECT)
1093 check_fixedpoint.log: check_fixedpoint$(EXEEXT)
1094 @p='check_fixedpoint$(EXEEXT)'; \
1095 b='check_fixedpoint'; \
10961121 $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
10971122 --log-file $$b.log --trs-file $$b.trs \
10981123 $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
11981223 mostlyclean-am
11991224
12001225 distclean: distclean-am
1201 -rm -f ./$(DEPDIR)/check_cdp.Po
1226 -rm -f ./$(DEPDIR)/check_bitmap.Po
1227 -rm -f ./$(DEPDIR)/check_cdp.Po
12021228 -rm -f ./$(DEPDIR)/check_edp.Po
12031229 -rm -f ./$(DEPDIR)/check_fixedpoint.Po
12041230 -rm -f ./$(DEPDIR)/check_lldp.Po
12531279 installcheck-am:
12541280
12551281 maintainer-clean: maintainer-clean-am
1256 -rm -f ./$(DEPDIR)/check_cdp.Po
1282 -rm -f ./$(DEPDIR)/check_bitmap.Po
1283 -rm -f ./$(DEPDIR)/check_cdp.Po
12571284 -rm -f ./$(DEPDIR)/check_edp.Po
12581285 -rm -f ./$(DEPDIR)/check_fixedpoint.Po
12591286 -rm -f ./$(DEPDIR)/check_lldp.Po
0 /* -*- mode: c; c-file-style: "openbsd" -*- */
1 /*
2 * Copyright (c) 2020 Vincent Bernat <bernat@luffy.cx>
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <check.h>
18
19 #include "../src/daemon/lldpd.h"
20
21 START_TEST(test_empty) {
22 uint32_t vlan_bmap[VLAN_BITMAP_LEN] = {};
23 ck_assert(bitmap_isempty(vlan_bmap));
24 ck_assert_int_eq(bitmap_numbits(vlan_bmap), 0);
25 }
26 END_TEST
27
28 START_TEST(test_first_bit) {
29 uint32_t vlan_bmap[VLAN_BITMAP_LEN] = {};
30 bitmap_set(vlan_bmap, 1);
31 ck_assert_int_eq(vlan_bmap[0], 2);
32 ck_assert_int_eq(bitmap_numbits(vlan_bmap), 1);
33 }
34 END_TEST
35
36 START_TEST(test_some_bits) {
37 uint32_t vlan_bmap[VLAN_BITMAP_LEN] = {};
38 bitmap_set(vlan_bmap, 1);
39 bitmap_set(vlan_bmap, 6);
40 bitmap_set(vlan_bmap, 31);
41 bitmap_set(vlan_bmap, 50);
42 ck_assert_int_eq(vlan_bmap[0], (1L << 1) | (1L << 6) | (1L << 31));
43 ck_assert_int_eq(vlan_bmap[1], (1L << (50-32)));
44 ck_assert_int_eq(vlan_bmap[2], 0);
45 ck_assert_int_eq(bitmap_numbits(vlan_bmap), 4);
46 }
47 END_TEST
48
49 Suite *
50 bitmap_suite(void)
51 {
52 Suite *s = suite_create("Bitmap handling");
53
54 TCase *tc_bitmap = tcase_create("Bitmap handling");
55 tcase_add_test(tc_bitmap, test_empty);
56 tcase_add_test(tc_bitmap, test_first_bit);
57 tcase_add_test(tc_bitmap, test_some_bits);
58 suite_add_tcase(s, tc_bitmap);
59
60 return s;
61 }
62
63 int
64 main()
65 {
66 int number_failed;
67 Suite *s = bitmap_suite();
68 SRunner *sr = srunner_create(s);
69 srunner_run_all(sr, CK_ENV);
70 number_failed = srunner_ntests_failed(sr);
71 srunner_free(sr);
72 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
73 }
3131 /* Our test config */
3232 struct lldpd test_cfg = {
3333 .g_config = {
34 .c_tx_interval = 30,
34 .c_tx_interval = 30000,
35 .c_tx_hold = 2,
3536 .c_ttl = 60,
3637 .c_smart = 0
3738 }