From 5c91e81e743bcaffaf2be0671c0d159c14890049 Mon Sep 17 00:00:00 2001 From: Christophe Fontaine Date: Mon, 2 Dec 2024 08:49:29 +0000 Subject: [PATCH] infra: forbid manual deletion of loopback iface Loopback interfaces are created/deleted upon vrf creation and deleation. Forbid the user to delete it. Signed-off-by: Christophe Fontaine --- modules/infra/api/iface.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/infra/api/iface.c b/modules/infra/api/iface.c index e4060ca4..e5718e26 100644 --- a/modules/infra/api/iface.c +++ b/modules/infra/api/iface.c @@ -53,8 +53,17 @@ static struct api_out iface_add(const void *request, void **response) { static struct api_out iface_del(const void *request, void ** /*response*/) { const struct gr_infra_iface_del_req *req = request; + struct iface *iface; int ret; + // Loopback interfaces are special, and are deleted + // when the last interface of a VRF is destroyed. + if ((iface = iface_from_id(req->iface_id)) == NULL) + return api_out(ENODEV, 0); + + if (iface->type_id == GR_IFACE_TYPE_LOOPBACK) + return api_out(EINVAL, 0); + ret = iface_destroy(req->iface_id); return api_out(-ret, 0);