Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 09 Mar 2023 16:38:14 +0100
From:      Kristof Provost <kp@FreeBSD.org>
To:        "Alexander V. Chernikov" <melifaro@FreeBSD.org>
Cc:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   Re: git: 7e5bf68495cc - main - netlink: add netlink support
Message-ID:  <3D3095AE-60CC-4CCD-8C8A-A6E53EEB6A8A@FreeBSD.org>
In-Reply-To: <202210011419.291EJ3aa000309@gitrepo.freebsd.org>
References:  <202210011419.291EJ3aa000309@gitrepo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--=_MailMate_4A1767AD-0372-4A68-B5E4-5EDABA9FD19E_=
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

On 1 Oct 2022, at 16:19, Alexander V. Chernikov wrote:
> The branch main has been updated by melifaro:
>
> URL: =

> https://cgit.FreeBSD.org/src/commit/?id=3D7e5bf68495cc0a8c9793a338a8a02=
009a7f6dbb6
>
> commit 7e5bf68495cc0a8c9793a338a8a02009a7f6dbb6
> Author:     Alexander V. Chernikov <melifaro@FreeBSD.org>
> AuthorDate: 2022-01-20 21:39:21 +0000
> Commit:     Alexander V. Chernikov <melifaro@FreeBSD.org>
> CommitDate: 2022-10-01 14:15:35 +0000
>
>     netlink: add netlink support
>
>     Netlinks is a communication protocol currently used in Linux =

> kernel to modify,
>      read and subscribe for nearly all networking state. Interfaces, =

> addresses, routes,
>      firewall, fibs, vnets, etc are controlled via netlink.
>     It is async, TLV-based protocol, providing 1-1 and 1-many =

> communications.
>
>     The current implementation supports the subset of NETLINK_ROUTE
>     family. To be more specific, the following is supported:
>     * Dumps:
>      - routes
>      - nexthops / nexthop groups
>      - interfaces
>      - interface addresses
>      - neighbors (arp/ndp)
>     * Notifications:
>      - interface arrival/departure
>      - interface address arrival/departure
>      - route addition/deletion
>     * Modifications:
>      - adding/deleting routes
>      - adding/deleting nexthops/nexthops groups
>      - adding/deleting neghbors
>      - adding/deleting interfaces (basic support only)
>     * Rtsock interaction
>      - route events are bridged both ways
>
>     The implementation also supports the NETLINK_GENERIC family =

> framework.
>
>     Implementation notes:
>     Netlink is implemented via loadable/unloadable kernel module,
>      not touching many kernel parts.
>     Each netlink socket uses dedicated taskqueue to support async =

> operations
>      that can sleep, such as interface creation. All message =

> processing is
>      performed within these taskqueues.
>
>     Compatibility:
>     Most of the Netlink data models specified above maps to FreeBSD =

> concepts
>      nicely. Unmodified ip(8) binary correctly works with
>     interfaces, addresses, routes, nexthops and nexthop groups. Some
>     software such as net/bird require header-only modifications to =

> compile
>     and work with FreeBSD netlink.
>
>     Reviewed by:    imp
>     Differential Revision: https://reviews.freebsd.org/D36002
>     MFC after:      2 months
> ---
>  etc/mtree/BSD.include.dist           |    4 +
>  sys/modules/Makefile                 |    1 +
>  sys/modules/netlink/Makefile         |   17 +
>  sys/net/route.c                      |   11 +
>  sys/net/route/route_ctl.h            |    7 +
>  sys/net/rtsock.c                     |   42 ++
>  sys/netlink/netlink.h                |  257 +++++++++
>  sys/netlink/netlink_ctl.h            |  102 ++++
>  sys/netlink/netlink_debug.h          |   82 +++
>  sys/netlink/netlink_domain.c         |  689 +++++++++++++++++++++++
>  sys/netlink/netlink_generic.c        |  472 ++++++++++++++++
>  sys/netlink/netlink_generic.h        |  112 ++++
>  sys/netlink/netlink_io.c             |  528 ++++++++++++++++++
>  sys/netlink/netlink_linux.h          |   54 ++
>  sys/netlink/netlink_message_parser.c |  472 ++++++++++++++++
>  sys/netlink/netlink_message_parser.h |  270 +++++++++
>  sys/netlink/netlink_message_writer.c |  686 +++++++++++++++++++++++
>  sys/netlink/netlink_message_writer.h |  250 +++++++++
>  sys/netlink/netlink_module.c         |  228 ++++++++
>  sys/netlink/netlink_route.c          |  135 +++++
>  sys/netlink/netlink_route.h          |   43 ++
>  sys/netlink/netlink_var.h            |  142 +++++
>  sys/netlink/route/common.h           |  213 ++++++++
>  sys/netlink/route/iface.c            |  857 =

> +++++++++++++++++++++++++++++
>  sys/netlink/route/iface_drivers.c    |  165 ++++++
>  sys/netlink/route/ifaddrs.h          |   90 +++
>  sys/netlink/route/interface.h        |  245 +++++++++
>  sys/netlink/route/neigh.c            |  571 +++++++++++++++++++
>  sys/netlink/route/neigh.h            |  105 ++++
>  sys/netlink/route/nexthop.c          | 1000 =

> ++++++++++++++++++++++++++++++++++
>  sys/netlink/route/nexthop.h          |  102 ++++
>  sys/netlink/route/route.c            |  972 =

> +++++++++++++++++++++++++++++++++
>  sys/netlink/route/route.h            |  366 +++++++++++++
>  sys/netlink/route/route_var.h        |  101 ++++
>  34 files changed, 9391 insertions(+)
>
> diff --git a/sys/netlink/netlink.h b/sys/netlink/netlink.h
> new file mode 100644
> index 000000000000..6a68dcec1382
> --- /dev/null
> +++ b/sys/netlink/netlink.h
> @@ -0,0 +1,257 @@
> +/*-
> + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
> + *
> + * Copyright (c) 2021 Ng Peng Nam Sean
> + * Copyright (c) 2022 Alexander V. Chernikov <melifaro@FreeBSD.org>
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above =

> copyright
> + *    notice, this list of conditions and the following disclaimer in =

> the
> + *    documentation and/or other materials provided with the =

> distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' =

> AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, =

> THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR =

> PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE =

> LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR =

> CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE =

> GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS =

> INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN =

> CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN =

> ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE =

> POSSIBILITY OF
> + * SUCH DAMAGE.
> + *
> + * Copyright (C) The Internet Society (2003).  All Rights Reserved.
> + *
> + * This document and translations of it may be copied and furnished =

> to
> + * others, and derivative works that comment on or otherwise explain =

> it
> + * or assist in its implementation may be prepared, copied, published
> + * and distributed, in whole or in part, without restriction of any
> + * kind, provided that the above copyright notice and this paragraph =

> are
> + * included on all such copies and derivative works.  However, this
> + * document itself may not be modified in any way, such as by =

> removing
> + * the copyright notice or references to the Internet Society or =

> other
> + * Internet organizations, except as needed for the purpose of
> + * developing Internet standards in which case the procedures for
> + * copyrights defined in the Internet Standards process must be
> + * followed, or as required to translate it into languages other than
> + * English.
> + *
> + * The limited permissions granted above are perpetual and will not =

> be
> + * revoked by the Internet Society or its successors or assignees.
> + *
> + * This document and the information contained herein is provided on =

> an
> + * "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET =

> ENGINEERING
> + * TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
> + * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
> + * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
> + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
> +
> + */
> +
> +/*
> + * This file contains structures and constants for RFC 3549 (Netlink)
> + * protocol. Some values have been taken from Linux implementation.
> + */
> +
> +#ifndef _NETLINK_NETLINK_H_
> +#define _NETLINK_NETLINK_H_
> +
> +#include <sys/types.h>
> +#include <sys/socket.h>
> +
> +struct sockaddr_nl {
> +	uint8_t		nl_len;		/* sizeof(sockaddr_nl) */
> +	sa_family_t	nl_family;	/* netlink family */
> +	uint16_t	nl_pad;		/* reserved, set to 0 */
> +	uint32_t	nl_pid;		/* desired port ID, 0 for auto-select */
> +	uint32_t	nl_groups;	/* multicast groups mask to bind to */
> +};
> +
> +#define	SOL_NETLINK			270
> +
> +/* Netlink socket options */
> +#define NETLINK_ADD_MEMBERSHIP		1 /* Subscribe for the specified =

> group notifications */
> +#define NETLINK_DROP_MEMBERSHIP		2 /* Unsubscribe from the specified =

> group */
> +#define NETLINK_PKTINFO			3 /* XXX: not supported */
> +#define NETLINK_BROADCAST_ERROR		4 /* XXX: not supported */
> +#define NETLINK_NO_ENOBUFS		5 /* XXX: not supported */
> +#define NETLINK_RX_RING			6 /* XXX: not supported */
> +#define NETLINK_TX_RING			7 /* XXX: not supported */
> +#define NETLINK_LISTEN_ALL_NSID		8 /* XXX: not supported */
> +
> +#define NETLINK_LIST_MEMBERSHIPS	9
> +#define NETLINK_CAP_ACK			10 /* Send only original message header in =

> the reply */
> +#define NETLINK_EXT_ACK			11 /* Ack support for receiving additional =

> TLVs in ack */
> +#define NETLINK_GET_STRICT_CHK		12 /* Strict header checking */
> +
> +
> +/*
> + * RFC 3549, 2.3.2 Netlink Message Header
> + */
> +struct nlmsghdr {
> +	uint32_t nlmsg_len;   /* Length of message including header */
> +	uint16_t nlmsg_type;  /* Message type identifier */
> +	uint16_t nlmsg_flags; /* Flags (NLM_F_) */
> +	uint32_t nlmsg_seq;   /* Sequence number */
> +	uint32_t nlmsg_pid;   /* Sending process port ID */
> +};
> +
> +/*
> + * RFC 3549, 2.3.2 standard flag bits (nlmsg_flags)
> + */
> +#define NLM_F_REQUEST		0x01	/* Indicateds request to kernel */
> +#define NLM_F_MULTI		0x02	/* Message is part of a group terminated by =

> NLMSG_DONE msg */
> +#define NLM_F_ACK		0x04	/* Reply with ack message containing =

> resulting error code */
> +#define NLM_F_ECHO		0x08	/* (not supported) Echo this request back */
> +#define NLM_F_DUMP_INTR		0x10	/* Dump was inconsistent due to =

> sequence change */
> +#define NLM_F_DUMP_FILTERED	0x20	/* Dump was filtered as requested */
> +
> +/*
> + * RFC 3549, 2.3.2 Additional flag bits for GET requests
> + */
> +#define NLM_F_ROOT		0x100	/* Return the complete table */
> +#define NLM_F_MATCH		0x200	/* Return all entries matching criteria */
> +#define NLM_F_ATOMIC		0x400	/* Return an atomic snapshot (ignored) */
> +#define NLM_F_DUMP		(NLM_F_ROOT | NLM_F_MATCH)
> +
> +/*
> + * RFC 3549, 2.3.2 Additional flag bits for NEW requests
> + */
> +#define NLM_F_REPLACE		0x100	/* Replace existing matching config =

> object */
> +#define NLM_F_EXCL		0x200	/* Don't replace the object if exists */
> +#define NLM_F_CREATE		0x400	/* Create if it does not exist */
> +#define NLM_F_APPEND		0x800	/* Add to end of list */
> +
> +/* Modifiers to DELETE requests */
> +#define NLM_F_NONREC		0x100	/* Do not delete recursively */
> +
> +/* Flags for ACK message */
> +#define NLM_F_CAPPED		0x100	/* request was capped */
> +#define NLM_F_ACK_TLVS		0x200	/* extended ACK TVLs were included */
> +
> +/*
> + * RFC 3549, 2.3.2 standard message types (nlmsg_type).
> + */
> +#define NLMSG_NOOP		0x1	/* Message is ignored. */
> +#define NLMSG_ERROR		0x2	/* reply error code reporting */
> +#define NLMSG_DONE		0x3	/* Message terminates a multipart message. */
> +#define NLMSG_OVERRUN		0x4	/* overrun detected, data is lost */
> +
> +#define NLMSG_MIN_TYPE		0x10	/* < 0x10: reserved control messages */
> +
> +/*
> + * Defition of numbers assigned to the netlink subsystems.
> + */
> +#define NETLINK_ROUTE		0	/* Routing/device hook */
> +#define NETLINK_UNUSED		1	/* not supported */
> +#define NETLINK_USERSOCK	2	/* not supported */
> +#define NETLINK_FIREWALL	3	/* not supported */
> +#define NETLINK_SOCK_DIAG	4	/* not supported */
> +#define NETLINK_NFLOG		5	/* not supported */
> +#define NETLINK_XFRM		6	/* (not supported) PF_SETKEY */
> +#define NETLINK_SELINUX		7	/* not supported */
> +#define NETLINK_ISCSI		8	/* not supported */
> +#define NETLINK_AUDIT		9	/* not supported */
> +#define NETLINK_FIB_LOOKUP	10	/* not supported */
> +#define NETLINK_CONNECTOR	11	/* not supported */
> +#define NETLINK_NETFILTER	12	/* not supported */
> +#define NETLINK_IP6_FW		13	/* not supported  */
> +#define NETLINK_DNRTMSG		14	/* not supported */
> +#define NETLINK_KOBJECT_UEVENT	15	/* not supported */
> +#define NETLINK_GENERIC		16	/* Generic netlink (dynamic families) */
> +
So, really fun thing here, we also have `#define NETLINK_GENERIC 0` in =

sys/net/if_mib.h. (And that=E2=80=99s exposed to userspace, and used ther=
e, so =

we can=E2=80=99t just change that.)

Which leads to much fun if we decided to do something like including the =

netlink_generic header in other headers, so we can define messages that =

contain the genlmsghdr struct.

I ran into that experimenting with netlink for carp(4). I think I can =

work around it by adding a separate ip_carp_nl.h header for the netlink =

stuff, but sooner or later this is going to bite us.

Kristof


--=_MailMate_4A1767AD-0372-4A68-B5E4-5EDABA9FD19E_=
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html>
<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/xhtml; charset=3Dutf-8"=
>
</head>
<body><div style=3D"font-family: sans-serif;"><div class=3D"markdown" sty=
le=3D"white-space: normal;">
<p dir=3D"auto">On 1 Oct 2022, at 16:19, Alexander V. Chernikov wrote:</p=
>
</div><div class=3D"plaintext" style=3D"white-space: normal;"><blockquote=
 style=3D"margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #136=
BCE; color: #136BCE;"><p dir=3D"auto">The branch main has been updated by=
 melifaro:</p>
<p dir=3D"auto">URL: <a href=3D"https://cgit.FreeBSD.org/src/commit/?id=3D=
7e5bf68495cc0a8c9793a338a8a02009a7f6dbb6">https://cgit.FreeBSD.org/src/co=
mmit/?id=3D7e5bf68495cc0a8c9793a338a8a02009a7f6dbb6</a></p>
<p dir=3D"auto">commit 7e5bf68495cc0a8c9793a338a8a02009a7f6dbb6
<br>
Author:     Alexander V. Chernikov &lt;melifaro@FreeBSD.org&gt;
<br>
AuthorDate: 2022-01-20 21:39:21 +0000
<br>
Commit:     Alexander V. Chernikov &lt;melifaro@FreeBSD.org&gt;
<br>
CommitDate: 2022-10-01 14:15:35 +0000</p>
<p dir=3D"auto">    netlink: add netlink support</p>
<p dir=3D"auto">    Netlinks is a communication protocol currently used i=
n Linux kernel to modify,
<br>
     read and subscribe for nearly all networking state. Interfaces, addr=
esses, routes,
<br>
     firewall, fibs, vnets, etc are controlled via netlink.
<br>
    It is async, TLV-based protocol, providing 1-1 and 1-many communicati=
ons.</p>
<p dir=3D"auto">    The current implementation supports the subset of NET=
LINK_ROUTE
<br>
    family. To be more specific, the following is supported:
<br>
    * Dumps:
<br>
     - routes
<br>
     - nexthops / nexthop groups
<br>
     - interfaces
<br>
     - interface addresses
<br>
     - neighbors (arp/ndp)
<br>
    * Notifications:
<br>
     - interface arrival/departure
<br>
     - interface address arrival/departure
<br>
     - route addition/deletion
<br>
    * Modifications:
<br>
     - adding/deleting routes
<br>
     - adding/deleting nexthops/nexthops groups
<br>
     - adding/deleting neghbors
<br>
     - adding/deleting interfaces (basic support only)
<br>
    * Rtsock interaction
<br>
     - route events are bridged both ways</p>
<p dir=3D"auto">    The implementation also supports the NETLINK_GENERIC =
family framework.</p>
<p dir=3D"auto">    Implementation notes:
<br>
    Netlink is implemented via loadable/unloadable kernel module,
<br>
     not touching many kernel parts.
<br>
    Each netlink socket uses dedicated taskqueue to support async operati=
ons
<br>
     that can sleep, such as interface creation. All message processing i=
s
<br>
     performed within these taskqueues.</p>
<p dir=3D"auto">    Compatibility:
<br>
    Most of the Netlink data models specified above maps to FreeBSD conce=
pts
<br>
     nicely. Unmodified ip(8) binary correctly works with
<br>
    interfaces, addresses, routes, nexthops and nexthop groups. Some
<br>
    software such as net/bird require header-only modifications to compil=
e
<br>
    and work with FreeBSD netlink.</p>
<p dir=3D"auto">    Reviewed by:    imp
<br>
    Differential Revision: <a href=3D"https://reviews.freebsd.org/D36002"=
>https://reviews.freebsd.org/D36002</a>;
<br>
    MFC after:      2 months
<br>
---
<br>
 etc/mtree/BSD.include.dist           |    4 +
<br>
 sys/modules/Makefile                 |    1 +
<br>
 sys/modules/netlink/Makefile         |   17 +
<br>
 sys/net/route.c                      |   11 +
<br>
 sys/net/route/route_ctl.h            |    7 +
<br>
 sys/net/rtsock.c                     |   42 ++
<br>
 sys/netlink/netlink.h                |  257 +++++++++
<br>
 sys/netlink/netlink_ctl.h            |  102 ++++
<br>
 sys/netlink/netlink_debug.h          |   82 +++
<br>
 sys/netlink/netlink_domain.c         |  689 +++++++++++++++++++++++
<br>
 sys/netlink/netlink_generic.c        |  472 ++++++++++++++++
<br>
 sys/netlink/netlink_generic.h        |  112 ++++
<br>
 sys/netlink/netlink_io.c             |  528 ++++++++++++++++++
<br>
 sys/netlink/netlink_linux.h          |   54 ++
<br>
 sys/netlink/netlink_message_parser.c |  472 ++++++++++++++++
<br>
 sys/netlink/netlink_message_parser.h |  270 +++++++++
<br>
 sys/netlink/netlink_message_writer.c |  686 +++++++++++++++++++++++
<br>
 sys/netlink/netlink_message_writer.h |  250 +++++++++
<br>
 sys/netlink/netlink_module.c         |  228 ++++++++
<br>
 sys/netlink/netlink_route.c          |  135 +++++
<br>
 sys/netlink/netlink_route.h          |   43 ++
<br>
 sys/netlink/netlink_var.h            |  142 +++++
<br>
 sys/netlink/route/common.h           |  213 ++++++++
<br>
 sys/netlink/route/iface.c            |  857 ++++++++++++++++++++++++++++=
+
<br>
 sys/netlink/route/iface_drivers.c    |  165 ++++++
<br>
 sys/netlink/route/ifaddrs.h          |   90 +++
<br>
 sys/netlink/route/interface.h        |  245 +++++++++
<br>
 sys/netlink/route/neigh.c            |  571 +++++++++++++++++++
<br>
 sys/netlink/route/neigh.h            |  105 ++++
<br>
 sys/netlink/route/nexthop.c          | 1000 ++++++++++++++++++++++++++++=
++++++
<br>
 sys/netlink/route/nexthop.h          |  102 ++++
<br>
 sys/netlink/route/route.c            |  972 ++++++++++++++++++++++++++++=
+++++
<br>
 sys/netlink/route/route.h            |  366 +++++++++++++
<br>
 sys/netlink/route/route_var.h        |  101 ++++
<br>
 34 files changed, 9391 insertions(+)</p>
<p dir=3D"auto">diff --git a/sys/netlink/netlink.h b/sys/netlink/netlink.=
h
<br>
new file mode 100644
<br>
index 000000000000..6a68dcec1382
<br>
--- /dev/null
<br>
+++ b/sys/netlink/netlink.h
<br>
@@ -0,0 +1,257 @@
<br>
+/*-
<br>
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
<br>
+ *
<br>
+ * Copyright (c) 2021 Ng Peng Nam Sean
<br>
+ * Copyright (c) 2022 Alexander V. Chernikov &lt;melifaro@FreeBSD.org&gt=
;
<br>
+ *
<br>
+ * Redistribution and use in source and binary forms, with or without
<br>
+ * modification, are permitted provided that the following conditions
<br>
+ * are met:
<br>
+ * 1. Redistributions of source code must retain the above copyright
<br>
+ *    notice, this list of conditions and the following disclaimer.
<br>
+ * 2. Redistributions in binary form must reproduce the above copyright
<br>
+ *    notice, this list of conditions and the following disclaimer in th=
e
<br>
+ *    documentation and/or other materials provided with the distributio=
n.
<br>
+ *
<br>
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AN=
D
<br>
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE=

<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PU=
RPOSE
<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABL=
E
<br>
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUE=
NTIAL
<br>
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOO=
DS
<br>
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)=

<br>
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S=
TRICT
<br>
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY=
 WAY
<br>
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY O=
F
<br>
+ * SUCH DAMAGE.
<br>
+ *
<br>
+ * Copyright (C) The Internet Society (2003).  All Rights Reserved.
<br>
+ *
<br>
+ * This document and translations of it may be copied and furnished to
<br>
+ * others, and derivative works that comment on or otherwise explain it
<br>
+ * or assist in its implementation may be prepared, copied, published
<br>
+ * and distributed, in whole or in part, without restriction of any
<br>
+ * kind, provided that the above copyright notice and this paragraph are=

<br>
+ * included on all such copies and derivative works.  However, this
<br>
+ * document itself may not be modified in any way, such as by removing
<br>
+ * the copyright notice or references to the Internet Society or other
<br>
+ * Internet organizations, except as needed for the purpose of
<br>
+ * developing Internet standards in which case the procedures for
<br>
+ * copyrights defined in the Internet Standards process must be
<br>
+ * followed, or as required to translate it into languages other than
<br>
+ * English.
<br>
+ *
<br>
+ * The limited permissions granted above are perpetual and will not be
<br>
+ * revoked by the Internet Society or its successors or assignees.
<br>
+ *
<br>
+ * This document and the information contained herein is provided on an
<br>
+ * "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
<br>
+ * TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
<br>
+ * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
<br>
+ * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
<br>
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
<br>
+
<br>
+ */
<br>
+
<br>
+/*
<br>
+ * This file contains structures and constants for RFC 3549 (Netlink)
<br>
+ * protocol. Some values have been taken from Linux implementation.
<br>
+ */
<br>
+
<br>
+#ifndef _NETLINK_NETLINK_H_
<br>
+#define _NETLINK_NETLINK_H_
<br>
+
<br>
+#include &lt;sys/types.h&gt;
<br>
+#include &lt;sys/socket.h&gt;
<br>
+
<br>
+struct sockaddr_nl {
<br>
+	uint8_t		nl_len;		/* sizeof(sockaddr_nl) */
<br>
+	sa_family_t	nl_family;	/* netlink family */
<br>
+	uint16_t	nl_pad;		/* reserved, set to 0 */
<br>
+	uint32_t	nl_pid;		/* desired port ID, 0 for auto-select */
<br>
+	uint32_t	nl_groups;	/* multicast groups mask to bind to */
<br>
+};
<br>
+
<br>
+#define	SOL_NETLINK			270
<br>
+
<br>
+/* Netlink socket options */
<br>
+#define NETLINK_ADD_MEMBERSHIP		1 /* Subscribe for the specified group n=
otifications */
<br>
+#define NETLINK_DROP_MEMBERSHIP		2 /* Unsubscribe from the specified gro=
up */
<br>
+#define NETLINK_PKTINFO			3 /* XXX: not supported */
<br>
+#define NETLINK_BROADCAST_ERROR		4 /* XXX: not supported */
<br>
+#define NETLINK_NO_ENOBUFS		5 /* XXX: not supported */
<br>
+#define NETLINK_RX_RING			6 /* XXX: not supported */
<br>
+#define NETLINK_TX_RING			7 /* XXX: not supported */
<br>
+#define NETLINK_LISTEN_ALL_NSID		8 /* XXX: not supported */
<br>
+
<br>
+#define NETLINK_LIST_MEMBERSHIPS	9
<br>
+#define NETLINK_CAP_ACK			10 /* Send only original message header in the=
 reply */
<br>
+#define NETLINK_EXT_ACK			11 /* Ack support for receiving additional TLV=
s in ack */
<br>
+#define NETLINK_GET_STRICT_CHK		12 /* Strict header checking */
<br>
+
<br>
+
<br>
+/*
<br>
+ * RFC 3549, 2.3.2 Netlink Message Header
<br>
+ */
<br>
+struct nlmsghdr {
<br>
+	uint32_t nlmsg_len;   /* Length of message including header */
<br>
+	uint16_t nlmsg_type;  /* Message type identifier */
<br>
+	uint16_t nlmsg_flags; /* Flags (NLM_F_) */
<br>
+	uint32_t nlmsg_seq;   /* Sequence number */
<br>
+	uint32_t nlmsg_pid;   /* Sending process port ID */
<br>
+};
<br>
+
<br>
+/*
<br>
+ * RFC 3549, 2.3.2 standard flag bits (nlmsg_flags)
<br>
+ */
<br>
+#define NLM_F_REQUEST		0x01	/* Indicateds request to kernel */
<br>
+#define NLM_F_MULTI		0x02	/* Message is part of a group terminated by NL=
MSG_DONE msg */
<br>
+#define NLM_F_ACK		0x04	/* Reply with ack message containing resulting e=
rror code */
<br>
+#define NLM_F_ECHO		0x08	/* (not supported) Echo this request back */
<br>
+#define NLM_F_DUMP_INTR		0x10	/* Dump was inconsistent due to sequence c=
hange */
<br>
+#define NLM_F_DUMP_FILTERED	0x20	/* Dump was filtered as requested */
<br>
+
<br>
+/*
<br>
+ * RFC 3549, 2.3.2 Additional flag bits for GET requests
<br>
+ */
<br>
+#define NLM_F_ROOT		0x100	/* Return the complete table */
<br>
+#define NLM_F_MATCH		0x200	/* Return all entries matching criteria */
<br>
+#define NLM_F_ATOMIC		0x400	/* Return an atomic snapshot (ignored) */
<br>
+#define NLM_F_DUMP		(NLM_F_ROOT | NLM_F_MATCH)
<br>
+
<br>
+/*
<br>
+ * RFC 3549, 2.3.2 Additional flag bits for NEW requests
<br>
+ */
<br>
+#define NLM_F_REPLACE		0x100	/* Replace existing matching config object =
*/
<br>
+#define NLM_F_EXCL		0x200	/* Don't replace the object if exists */
<br>
+#define NLM_F_CREATE		0x400	/* Create if it does not exist */
<br>
+#define NLM_F_APPEND		0x800	/* Add to end of list */
<br>
+
<br>
+/* Modifiers to DELETE requests */
<br>
+#define NLM_F_NONREC		0x100	/* Do not delete recursively */
<br>
+
<br>
+/* Flags for ACK message */
<br>
+#define NLM_F_CAPPED		0x100	/* request was capped */
<br>
+#define NLM_F_ACK_TLVS		0x200	/* extended ACK TVLs were included */
<br>
+
<br>
+/*
<br>
+ * RFC 3549, 2.3.2 standard message types (nlmsg_type).
<br>
+ */
<br>
+#define NLMSG_NOOP		0x1	/* Message is ignored. */
<br>
+#define NLMSG_ERROR		0x2	/* reply error code reporting */
<br>
+#define NLMSG_DONE		0x3	/* Message terminates a multipart message. */
<br>
+#define NLMSG_OVERRUN		0x4	/* overrun detected, data is lost */
<br>
+
<br>
+#define NLMSG_MIN_TYPE		0x10	/* &lt; 0x10: reserved control messages */
<br>
+
<br>
+/*
<br>
+ * Defition of numbers assigned to the netlink subsystems.
<br>
+ */
<br>
+#define NETLINK_ROUTE		0	/* Routing/device hook */
<br>
+#define NETLINK_UNUSED		1	/* not supported */
<br>
+#define NETLINK_USERSOCK	2	/* not supported */
<br>
+#define NETLINK_FIREWALL	3	/* not supported */
<br>
+#define NETLINK_SOCK_DIAG	4	/* not supported */
<br>
+#define NETLINK_NFLOG		5	/* not supported */
<br>
+#define NETLINK_XFRM		6	/* (not supported) PF_SETKEY */
<br>
+#define NETLINK_SELINUX		7	/* not supported */
<br>
+#define NETLINK_ISCSI		8	/* not supported */
<br>
+#define NETLINK_AUDIT		9	/* not supported */
<br>
+#define NETLINK_FIB_LOOKUP	10	/* not supported */
<br>
+#define NETLINK_CONNECTOR	11	/* not supported */
<br>
+#define NETLINK_NETFILTER	12	/* not supported */
<br>
+#define NETLINK_IP6_FW		13	/* not supported  */
<br>
+#define NETLINK_DNRTMSG		14	/* not supported */
<br>
+#define NETLINK_KOBJECT_UEVENT	15	/* not supported */
<br>
+#define NETLINK_GENERIC		16	/* Generic netlink (dynamic families) */
<br>
+</p>
</blockquote></div>
<div class=3D"markdown" style=3D"white-space: normal;">
<p dir=3D"auto">So, really fun thing here, we also have <code style=3D"pa=
dding: 0 0.25em; background-color: #E4E4E4;">#define NETLINK_GENERIC 0</c=
ode> in sys/net/if_mib.h. (And that=E2=80=99s exposed to userspace, and u=
sed there, so we can=E2=80=99t just change that.)</p>
<p dir=3D"auto">Which leads to much fun if we decided to do something lik=
e including the netlink_generic header in other headers, so we can define=
 messages that contain the genlmsghdr struct.</p>
<p dir=3D"auto">I ran into that experimenting with netlink for carp(4). I=
 think I can work around it by adding a separate ip_carp_nl.h header for =
the netlink stuff, but sooner or later this is going to bite us.</p>
<p dir=3D"auto">Kristof</p>

</div>
</div>
</body>

</html>

--=_MailMate_4A1767AD-0372-4A68-B5E4-5EDABA9FD19E_=--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3D3095AE-60CC-4CCD-8C8A-A6E53EEB6A8A>