From: Yu Watanabe Date: Mon, 9 Sep 2024 18:18:19 +0000 (+0900) Subject: network/l2tp: refuse duplicated session name X-Git-Tag: v257-rc1~499^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=121d32b09c1675aa2dbe561f33f1695a1ae3fe26;p=thirdparty%2Fsystemd.git network/l2tp: refuse duplicated session name --- diff --git a/src/network/netdev/l2tp-tunnel.c b/src/network/netdev/l2tp-tunnel.c index 9f8287cb911..b9be66c1131 100644 --- a/src/network/netdev/l2tp-tunnel.c +++ b/src/network/netdev/l2tp-tunnel.c @@ -762,9 +762,12 @@ static void l2tp_tunnel_init(NetDev *netdev) { ##__VA_ARGS__); \ }) -static int l2tp_session_verify(L2tpSession *session) { +static int l2tp_session_verify(L2tpSession *session, Set **names) { + int r; + assert(session); assert(session->tunnel); + assert(names); if (section_is_invalid(session->section)) return -EINVAL; @@ -775,6 +778,15 @@ static int l2tp_session_verify(L2tpSession *session) { if (session->session_id == 0 || session->peer_session_id == 0) return log_session(session, "L2TP session without session IDs configured."); + if (streq(session->name, NETDEV(session->tunnel)->ifname)) + return log_session(session, "L2TP session name %s cannot be the same as the netdev name.", session->name); + + r = set_ensure_put(names, &string_hash_ops, session->name); + if (r < 0) + return log_oom(); + if (r == 0) + return log_session(session, "L2TP session name %s is duplicated.", session->name); + return 0; } @@ -799,8 +811,9 @@ static int netdev_l2tp_tunnel_verify(NetDev *netdev, const char *filename) { "%s: L2TP tunnel without tunnel IDs configured. Ignoring", filename); + _cleanup_set_free_ Set *names = NULL; ORDERED_HASHMAP_FOREACH(session, t->sessions_by_section) - if (l2tp_session_verify(session) < 0) + if (l2tp_session_verify(session, &names) < 0) l2tp_session_free(session); return 0;