From nobody Fri Jul 25 20:12:01 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bpfD21QG9z62Hf7; Fri, 25 Jul 2025 20:12:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bpfD202J7z3G8D; Fri, 25 Jul 2025 20:12:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753474322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=C6B5kf+jfF3DY0zxF1AGThlwq7g8Utbiy5BQRPBohzM=; b=X/qhIdxP05hIeLDu0xib7VDxdLo1UH0WVpJkdBixw+It0rWWKE/UAyBK9LW/IiPEjKlqOU 9j90AX4qNL+GIns54LouuWVNSZH21EF+Hj3QutN/sl4Q1VMFdbPt9onnWBuiyzy5yJFHHp QlbGiyaT3bVKtt873r0i+/JfJDIoFT/NhloYVaFruF1fWqkU56uowzlbeGfssj9Kd//rgm 7yIKlrz7558jytHsDxxegzZ1gmdfyIMR4xGW8qVh667MUO02Jr9csmA3b+AP9mjaG1R/m+ vQbjr1OsscDaHYekyAGYC9FvL0WWDCrMXfHX/VQ767X1A/2jOIlvvVCF4Busww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753474322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=C6B5kf+jfF3DY0zxF1AGThlwq7g8Utbiy5BQRPBohzM=; b=TT46TK5X3VpU0s0x9wZoY77Q0T0XqJKPfBVhMJvw5BTpkq6uPtJ0iTQfcuMlYXTN4Vy8NF 87en5BjeYU9j8TBj3wqRt+uWgxFkORKHeCwNGBTMFJphTuSDC654A5b1e9tcXeYpen6rQK Xr8eHcPYe0CK4KuNSaV2RCHLubAfGLY7xdoWgk5AUgF3fMhVgUqPn/5BL4oxrt+s/DQsAS egxctFyEpE8rIY4BOWRjM4FE6kfzOts4XXVJCfEPdMpTbUez4qDFkTYMiMIaEn6gwkNFBG 838GTeSkjTG1/lZ2x4QtvIj1+Ac5+ZQhpLfzNN6j2iLBXMgfk45qO56BFBgG0g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1753474322; a=rsa-sha256; cv=none; b=GJP/WQultuQGOOTIRw72neWdUEBEGdjOz3oXHdZh3VT04PbN+zC4s1s7UsZuvY97XvFLJ2 17zi1ox690a3ZSmmH/iN70hGYlanMJqlLuxv6j/wXmgu/1U3jg8pnWhlhtscR0vuKQrN00 RonZ/o8jaGSUyh8s2Fv1UUXTLRO8bcHeK8PLEfAx8wz0ad5U2lM6UNxvWfeLuT7plqdtee EjXEI5COkI2TTc7VL1Nl/33weOMp5rTXMfMyXpwcHGAqZG6a43m9Z5gn21dXp7pFSG+d+8 x4SrI8xNtRJXISDTes3mmp7RnM93YVrdENwrp8glkXaUUwPWcOs1YCkRdlming== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bpfD16XsQzymw; Fri, 25 Jul 2025 20:12:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 56PKC1cZ010117; Fri, 25 Jul 2025 20:12:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 56PKC1ia010114; Fri, 25 Jul 2025 20:12:01 GMT (envelope-from git) Date: Fri, 25 Jul 2025 20:12:01 GMT Message-Id: <202507252012.56PKC1ia010114@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: c8312acdc25b - main - bsnmpd: deprecate legacy UDP transport trans_udp.c List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c8312acdc25bfa9c67e153f7227bb5e7537cf01f Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=c8312acdc25bfa9c67e153f7227bb5e7537cf01f commit c8312acdc25bfa9c67e153f7227bb5e7537cf01f Author: Gleb Smirnoff AuthorDate: 2025-07-25 20:09:29 +0000 Commit: Gleb Smirnoff CommitDate: 2025-07-25 20:09:29 +0000 bsnmpd: deprecate legacy UDP transport trans_udp.c Since 04d1781439aa we have a more generic trans_inet.c, that supports IPv6 and can be extended further. The default config file we ship was switched to the new transport since 12.1-RELEASE, so for most people deprecation would go unnoticed. Others [who never run etcupdate(8)] would need to merge a couple lines into their snmpd.config. This will be reflected in RELNOTES file. Reviewed by: harti Differential Revision: https://reviews.freebsd.org/D51359 --- contrib/bsnmp/snmpd/main.c | 3 - contrib/bsnmp/snmpd/trans_udp.c | 438 ---------------------------------------- contrib/bsnmp/snmpd/tree.def | 9 - usr.sbin/bsnmpd/bsnmpd/Makefile | 2 +- 4 files changed, 1 insertion(+), 451 deletions(-) diff --git a/contrib/bsnmp/snmpd/main.c b/contrib/bsnmp/snmpd/main.c index c77572934d24..f71e3f9515f2 100644 --- a/contrib/bsnmp/snmpd/main.c +++ b/contrib/bsnmp/snmpd/main.c @@ -237,7 +237,6 @@ static struct request_info req; #endif /* transports */ -extern const struct transport_def udp_trans; extern const struct transport_def lsock_trans; struct transport_list transport_list = TAILQ_HEAD_INITIALIZER(transport_list); @@ -1661,8 +1660,6 @@ main(int argc, char *argv[]) syslog(LOG_ERR, "atexit failed: %m"); exit(1); } - if (udp_trans.start() != SNMP_ERR_NOERROR) - syslog(LOG_WARNING, "cannot start UDP transport"); if (lsock_trans.start() != SNMP_ERR_NOERROR) syslog(LOG_WARNING, "cannot start LSOCK transport"); if (inet_trans.start() != SNMP_ERR_NOERROR) diff --git a/contrib/bsnmp/snmpd/trans_udp.c b/contrib/bsnmp/snmpd/trans_udp.c deleted file mode 100644 index 55824b82f6c8..000000000000 --- a/contrib/bsnmp/snmpd/trans_udp.c +++ /dev/null @@ -1,438 +0,0 @@ -/* - * Copyright (c) 2003 - * Fraunhofer Institute for Open Communication Systems (FhG Fokus). - * All rights reserved. - * - * Author: Harti Brandt - * - * 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 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 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. - * - * $Begemot: bsnmp/snmpd/trans_udp.c,v 1.5 2005/10/04 08:46:56 brandt_h Exp $ - * - * UDP transport - */ -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "snmpmod.h" -#include "snmpd.h" -#include "trans_udp.h" -#include "tree.h" -#include "oid.h" - -static int udp_start(void); -static int udp_stop(int); -static void udp_close_port(struct tport *); -static int udp_init_port(struct tport *); -static ssize_t udp_send(struct tport *, const u_char *, size_t, - const struct sockaddr *, size_t); -static ssize_t udp_recv(struct tport *, struct port_input *); - -/* exported */ -const struct transport_def udp_trans = { - .name = "udp", - .id = OIDX_begemotSnmpdTransUdp, - .start = udp_start, - .stop = udp_stop, - .close_port = udp_close_port, - .init_port = udp_init_port, - .send = udp_send, - .recv = udp_recv, -}; -static struct transport *my_trans; - -static int -udp_start(void) -{ - return (trans_register(&udp_trans, &my_trans)); -} - -static int -udp_stop(int force __unused) -{ - if (my_trans != NULL) - if (trans_unregister(my_trans) != 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); -} - -/* - * A UDP port is ready - */ -static void -udp_input(int fd __unused, void *udata) -{ - struct udp_port *p = udata; - - p->input.peerlen = sizeof(p->ret); - snmpd_input(&p->input, &p->tport); -} - -/* - * Create a UDP socket and bind it to the given port - */ -static int -udp_init_port(struct tport *tp) -{ - struct udp_port *p = (struct udp_port *)tp; - struct sockaddr_in addr; - u_int32_t ip; - const int on = 1; - - if ((p->input.fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { - syslog(LOG_ERR, "creating UDP socket: %m"); - return (SNMP_ERR_RES_UNAVAIL); - } - ip = (p->addr[0] << 24) | (p->addr[1] << 16) | (p->addr[2] << 8) | - p->addr[3]; - memset(&addr, 0, sizeof(addr)); - addr.sin_addr.s_addr = htonl(ip); - addr.sin_port = htons(p->port); - addr.sin_family = AF_INET; - addr.sin_len = sizeof(addr); - if (addr.sin_addr.s_addr == INADDR_ANY) { - if (setsockopt(p->input.fd, IPPROTO_IP, IP_RECVDSTADDR, &on, - sizeof(on)) == -1) { - syslog(LOG_ERR, "setsockopt(IP_RECVDSTADDR): %m"); - close(p->input.fd); - p->input.fd = -1; - return (SNMP_ERR_GENERR); - } - p->recvdstaddr = true; - } - if (bind(p->input.fd, (struct sockaddr *)&addr, sizeof(addr))) { - if (errno == EADDRNOTAVAIL) { - close(p->input.fd); - p->input.fd = -1; - return (SNMP_ERR_INCONS_NAME); - } - syslog(LOG_ERR, "bind: %s:%u %m", inet_ntoa(addr.sin_addr), - p->port); - close(p->input.fd); - p->input.fd = -1; - return (SNMP_ERR_GENERR); - } - if ((p->input.id = fd_select(p->input.fd, udp_input, - p, NULL)) == NULL) { - close(p->input.fd); - p->input.fd = -1; - return (SNMP_ERR_GENERR); - } - return (SNMP_ERR_NOERROR); -} - -/* - * Create a new SNMP Port object and start it, if we are not - * in initialization mode. The arguments are in host byte order. - */ -static int -udp_open_port(u_int8_t *addr, u_int32_t udp_port, struct udp_port **pp) -{ - struct udp_port *port; - int err; - - if (udp_port > 0xffff) - return (SNMP_ERR_NO_CREATION); - if ((port = malloc(sizeof(*port))) == NULL) - return (SNMP_ERR_GENERR); - memset(port, 0, sizeof(*port)); - - /* initialize common part */ - port->tport.index.len = 5; - port->tport.index.subs[0] = addr[0]; - port->tport.index.subs[1] = addr[1]; - port->tport.index.subs[2] = addr[2]; - port->tport.index.subs[3] = addr[3]; - port->tport.index.subs[4] = udp_port; - - port->addr[0] = addr[0]; - port->addr[1] = addr[1]; - port->addr[2] = addr[2]; - port->addr[3] = addr[3]; - port->port = udp_port; - - port->input.fd = -1; - port->input.id = NULL; - port->input.stream = 0; - port->input.cred = 0; - port->input.peer = (struct sockaddr *)&port->ret; - port->input.peerlen = sizeof(port->ret); - - trans_insert_port(my_trans, &port->tport); - - if (community != COMM_INITIALIZE && - (err = udp_init_port(&port->tport)) != SNMP_ERR_NOERROR) { - udp_close_port(&port->tport); - return (err); - } - *pp = port; - return (SNMP_ERR_NOERROR); -} - -/* - * Close an SNMP port - */ -static void -udp_close_port(struct tport *tp) -{ - struct udp_port *port = (struct udp_port *)tp; - - snmpd_input_close(&port->input); - trans_remove_port(tp); - free(port); -} - -/* - * Send something - */ -static ssize_t -udp_send(struct tport *tp, const u_char *buf, size_t len, - const struct sockaddr *addr, size_t addrlen) -{ - struct udp_port *p = (struct udp_port *)tp; - struct cmsghdr *cmsg; - struct msghdr msg; - char cbuf[CMSG_SPACE(sizeof(struct in_addr))]; - struct iovec iov; - - iov.iov_base = __DECONST(void*, buf); - iov.iov_len = len; - - msg.msg_flags = 0; - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_name = __DECONST(void *, addr); - msg.msg_namelen = addrlen; - - if (p->recvdstaddr) { - msg.msg_control = cbuf; - msg.msg_controllen = sizeof(cbuf); - - cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_level = IPPROTO_IP; - cmsg->cmsg_type = IP_SENDSRCADDR; - cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_addr)); - memcpy(CMSG_DATA(cmsg), &p->dstaddr, sizeof(struct in_addr)); - } else { - msg.msg_control = NULL; - msg.msg_controllen = 0; - } - - return (sendmsg(p->input.fd, &msg, 0)); -} - -static void -check_priv_dgram(struct port_input *pi, struct sockcred *cred) -{ - - /* process explicitly sends credentials */ - if (cred) - pi->priv = (cred->sc_euid == 0); - else - pi->priv = 0; -} - -/* - * Input from a datagram socket. - * Each receive should return one datagram. - */ -static ssize_t -udp_recv(struct tport *tp, struct port_input *pi) -{ - u_char embuf[1000]; - char cbuf[CMSG_SPACE(SOCKCREDSIZE(CMGROUP_MAX)) + - CMSG_SPACE(sizeof(struct in_addr))]; - struct udp_port *p = (struct udp_port *)tp; - struct msghdr msg; - struct iovec iov[1]; - ssize_t len; - struct cmsghdr *cmsg; - struct sockcred *cred = NULL; - - if (pi->buf == NULL) { - /* no buffer yet - allocate one */ - if ((pi->buf = buf_alloc(0)) == NULL) { - /* ups - could not get buffer. Read away input - * and drop it */ - (void)recvfrom(pi->fd, embuf, sizeof(embuf), - 0, NULL, NULL); - /* return error */ - return (-1); - } - pi->buflen = buf_size(0); - } - - /* try to get a message */ - msg.msg_name = pi->peer; - msg.msg_namelen = pi->peerlen; - msg.msg_iov = iov; - msg.msg_iovlen = 1; - memset(cbuf, 0, sizeof(cbuf)); - msg.msg_control = cbuf; - msg.msg_controllen = sizeof(cbuf); - msg.msg_flags = 0; - - iov[0].iov_base = pi->buf; - iov[0].iov_len = pi->buflen; - - len = recvmsg(pi->fd, &msg, 0); - - if (len == -1 || len == 0) - /* receive error */ - return (-1); - - if (msg.msg_flags & MSG_TRUNC) { - /* truncated - drop */ - snmpd_stats.silentDrops++; - snmpd_stats.inTooLong++; - return (-1); - } - - pi->length = (size_t)len; - - for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; - cmsg = CMSG_NXTHDR(&msg, cmsg)) { - if (cmsg->cmsg_level == IPPROTO_IP && - cmsg->cmsg_type == IP_RECVDSTADDR) - memcpy(&p->dstaddr, CMSG_DATA(cmsg), - sizeof(struct in_addr)); - if (cmsg->cmsg_level == SOL_SOCKET && - cmsg->cmsg_type == SCM_CREDS) - cred = (struct sockcred *)(void *)CMSG_DATA(cmsg); - } - - if (pi->cred) - check_priv_dgram(pi, cred); - - return (0); -} - -/* - * Port table - */ -int -op_snmp_port(struct snmp_context *ctx, struct snmp_value *value, - u_int sub, u_int iidx, enum snmp_op op) -{ - asn_subid_t which = value->var.subs[sub-1]; - struct udp_port *p; - u_int8_t addr[4]; - u_int32_t port; - - switch (op) { - - case SNMP_OP_GETNEXT: - if ((p = (struct udp_port *)trans_next_port(my_trans, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - index_append(&value->var, sub, &p->tport.index); - break; - - case SNMP_OP_GET: - if ((p = (struct udp_port *)trans_find_port(my_trans, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_SET: - p = (struct udp_port *)trans_find_port(my_trans, - &value->var, sub); - ctx->scratch->int1 = (p != NULL); - - if (which != LEAF_begemotSnmpdPortStatus) - abort(); - if (!TRUTH_OK(value->v.integer)) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int2 = TRUTH_GET(value->v.integer); - - if (ctx->scratch->int2) { - /* open an SNMP port */ - if (p != NULL) - /* already open - do nothing */ - return (SNMP_ERR_NOERROR); - - if (index_decode(&value->var, sub, iidx, addr, &port)) - return (SNMP_ERR_NO_CREATION); - return (udp_open_port(addr, port, &p)); - - } else { - /* close SNMP port - do in commit */ - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_ROLLBACK: - p = (struct udp_port *)trans_find_port(my_trans, - &value->var, sub); - if (ctx->scratch->int1 == 0) { - /* did not exist */ - if (ctx->scratch->int2 == 1) { - /* created */ - if (p != NULL) - udp_close_port(&p->tport); - } - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - p = (struct udp_port *)trans_find_port(my_trans, - &value->var, sub); - if (ctx->scratch->int1 == 1) { - /* did exist */ - if (ctx->scratch->int2 == 0) { - /* delete */ - if (p != NULL) - udp_close_port(&p->tport); - } - } - return (SNMP_ERR_NOERROR); - - default: - abort(); - } - - /* - * Come here to fetch the value - */ - switch (which) { - - case LEAF_begemotSnmpdPortStatus: - value->v.integer = 1; - break; - - default: - abort(); - } - - return (SNMP_ERR_NOERROR); -} diff --git a/contrib/bsnmp/snmpd/tree.def b/contrib/bsnmp/snmpd/tree.def index 61b581120528..074a6e7e5390 100644 --- a/contrib/bsnmp/snmpd/tree.def +++ b/contrib/bsnmp/snmpd/tree.def @@ -117,15 +117,6 @@ typedef BegemotSnmpdTransportProto ENUM ( ) ) # -# Port table -# - (4 begemotSnmpdPortTable - (1 begemotSnmpdPortEntry : IPADDRESS INTEGER op_snmp_port - (1 begemotSnmpdPortAddress IPADDRESS) - (2 begemotSnmpdPortPort UNSIGNED32) - (3 begemotSnmpdPortStatus INTEGER GET SET) - )) -# # Community table # (5 begemotSnmpdCommunityTable diff --git a/usr.sbin/bsnmpd/bsnmpd/Makefile b/usr.sbin/bsnmpd/bsnmpd/Makefile index e7c7a87eec7c..601fc31ec475 100644 --- a/usr.sbin/bsnmpd/bsnmpd/Makefile +++ b/usr.sbin/bsnmpd/bsnmpd/Makefile @@ -9,7 +9,7 @@ CONTRIB=${SRCTOP}/contrib/bsnmp CONFS= snmpd.config CONFSMODE= 600 PROG= bsnmpd -SRCS= main.c action.c config.c export.c trap.c trans_udp.c trans_lsock.c +SRCS= main.c action.c config.c export.c trap.c trans_lsock.c SRCS+= trans_inet.c oid.h tree.c tree.h XSYM= snmpMIB begemotSnmpdModuleTable begemotSnmpd begemotTrapSinkTable \ sysUpTime snmpTrapOID coldStart authenticationFailure \