From patchwork Thu Dec 14 17:52:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?G=C3=A9rald_Colangelo?= X-Patchwork-Id: 1876335 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=weblib.eu header.i=@weblib.eu header.a=rsa-sha256 header.s=google header.b=lNXOtlRm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=netfilter-devel+bounces-366-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Srg126KNmz20LT for ; Fri, 15 Dec 2023 04:52:38 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4EECC28297C for ; Thu, 14 Dec 2023 17:52:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 52247675DE; Thu, 14 Dec 2023 17:52:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=weblib.eu header.i=@weblib.eu header.b="lNXOtlRm" X-Original-To: netfilter-devel@vger.kernel.org Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A59C410A for ; Thu, 14 Dec 2023 09:52:24 -0800 (PST) Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2cc49101044so5527681fa.1 for ; Thu, 14 Dec 2023 09:52:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=weblib.eu; s=google; t=1702576342; x=1703181142; darn=vger.kernel.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=BfHbuPnwUDC8TtVbPO8ONYMuT9tPnt+O41UrkiC1HI8=; b=lNXOtlRmOnynnbQ7sJC1/ZML4XoUqpZ/FWj/t1e2JWkyDU287TRcTGKverXxVVI/T1 RACFTrwHJtF0o8KSrKf1SACXcxCJc3S+jtFekvLDCipca0MyymWlJ1Sp/0P2wKah4T7S WQLiQy7SGiS18TKHKIZxs9RxB1cb1Rd3Qu3MuP8mGXMlGgNrnE5u0n7ZC9Oi1biVesEx 6FDa0Kus25UipouG2o/EZerNLroTbkDPQhGtqi3ymhUSgh8WbG+2qIEaOxkBmqa+FHuM N52Qm2ByDZQUr4vB3fbOImRPQYBqpg5r9JgFJItaSlG5AiLQUseFl/aAbC+NQ/3fYUdi ciJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702576342; x=1703181142; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=BfHbuPnwUDC8TtVbPO8ONYMuT9tPnt+O41UrkiC1HI8=; b=mqhxipxiP1J+rEicACgHGE0cpKWPijxgRX6ImlD2AueaHgpklKD3W4ckqFQtRZMMye 9ZCxIyXlyolrxMi30ANE4CoiV/azJIBrkBoDx4AIJBpqCwNledtTqVLecPOmllg9NwmO veqy39QIhhB6ZFKF1EEVUsqDHEjQYiozBY/YByoOA1em/XJeNrkzoUmzZZGzr9wWR9I2 M8d5sjLl3Du6YvKMWeN4S06YGGDgbCrhw6yPYL5wwjn0zvH3SdB0wNDHPbbfzahQeGYq QpSkPZf6Yyhe8Y5huMeurnuWuzULJz48KOU5MczvMD9EuVfrw1G1Gogp3xhSX0haa3e+ B9cg== X-Gm-Message-State: AOJu0Yx8T4Zqh0xqB0GHThKCEDA0N5R6BD5UTnRgo8GlbySimHHj25mx ECextb4eUPqtAL+VX0R0jPL0AyrQNJwg4kQZ9BfHrXMWVbvWEW1/ X-Google-Smtp-Source: AGHT+IEKz7B+xGVrJySegmzivoO6Zitdjm+R8vPwbrYB0VdmtxIS952IpXBmIrLpJcG6N6ZUEd9HcKZmdxv2MkZ0Xgg= X-Received: by 2002:ac2:5589:0:b0:50b:fb07:ccde with SMTP id v9-20020ac25589000000b0050bfb07ccdemr2014318lfg.51.1702576342280; Thu, 14 Dec 2023 09:52:22 -0800 (PST) Precedence: bulk X-Mailing-List: netfilter-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: =?utf-8?q?G=C3=A9rald_Colangelo?= Date: Thu, 14 Dec 2023 18:52:10 +0100 Message-ID: Subject: ulogd / JSON output / enhancement proposal To: netfilter-devel@vger.kernel.org Hello everyone, To complete my previous message, here is a patch for ulogd_output_JSON.c (latest version) that implements a "softfail" configuration option. If set to 1, error while connecting to unix socket are ignored during startup and plugin will attempt to connect next time it will be triggered. This may be helpful when the software that must listen on unix socket takes too long to launch. Best regards, 51a52 > #define softfail_ce(x) (x->ces[JSON_CONF_SOFTFAIL]) 53a55,57 > > static int json_init_connect(struct ulogd_pluginstance *upi); > 61a66,67 > int started; > int softfail; 81c87,88 < JSON_CONF_MAX --- > JSON_CONF_SOFTFAIL, > JSON_CONF_MAX, 140a148,153 > [JSON_CONF_SOFTFAIL] = { > .key = "softfail", > .type = CONFIG_TYPE_INT, > .options = CONFIG_OPT_NONE, > .u = { .value = 0 }, > }, 283a297,313 > if (opi->softfail == 1 && opi->started == 0) { > int state; > state = json_init_connect(upi); > /* Not connected but softfail, skip packet */ > if (state == 1) { > ulogd_log(ULOGD_DEBUG, "unable to connect to json but softail=1, packet will be ignored.\n"); > return ULOGD_IRET_OK; > } > else if (state == 0) { > ulogd_log(ULOGD_DEBUG, "successfully connected json endpoint!\n"); > } > else { > ulogd_log(ULOGD_FATAL, "not supposed to happen !\n"); > return ULOGD_IRET_STOP; > } > } > 500a531,535 > if ( softfail_ce(upi->config_kset).u.value != 0 ) > op->softfail = 1; > else > op->softfail = 0; > 542a578,609 > > /* > return value: > 0: connection is OK. > 1: connection is KO but softfail=1 (retry later). > -1: connection is KO and softfail=0 (fail). > */ > static int json_init_connect(struct ulogd_pluginstance *upi) > { > struct json_priv *op = (struct json_priv *) &upi->private; > int ret; > ret = 0; > if (op->mode == JSON_MODE_FILE) > ret = json_init_file(upi); > else > ret = json_init_socket(upi); > > /* failed starting and softfail_start != 0 */ > if (ret != 0) { > if(op->softfail == 1) { > ulogd_log(ULOGD_INFO, "can't init output, but softfail=1. Will retry later.\n"); > op->started = 0; > return 1; > } else { > ulogd_log(ULOGD_FATAL, "can't connect and softfail=0, fatal error.\n"); > return -1; > } > } > op->started = 1; > return 0; > } > 561,564c628 < if (op->mode == JSON_MODE_FILE) < return json_init_file(upi); < else < return json_init_socket(upi); --- > return json_init_connect(upi) == -1 ? -1 : 0;