From patchwork Tue Mar 19 19:17:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naveen Yerramneni X-Patchwork-Id: 1913757 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nutanix.com header.i=@nutanix.com header.a=rsa-sha256 header.s=proofpoint20171006 header.b=swz6ESpQ; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nutanix.com header.i=@nutanix.com header.a=rsa-sha256 header.s=selector1 header.b=qI2llB5U; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzhN95gSPz1yWs for ; Wed, 20 Mar 2024 06:18:49 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 834C88125B; Tue, 19 Mar 2024 19:18:47 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 87BE4vt9pQB4; Tue, 19 Mar 2024 19:18:46 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 01F8180F4C Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=nutanix.com header.i=@nutanix.com header.a=rsa-sha256 header.s=proofpoint20171006 header.b=swz6ESpQ; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=nutanix.com header.i=@nutanix.com header.a=rsa-sha256 header.s=selector1 header.b=qI2llB5U Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 01F8180F4C; Tue, 19 Mar 2024 19:18:46 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id CD157C0072; Tue, 19 Mar 2024 19:18:45 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8F245C0037 for ; Tue, 19 Mar 2024 19:18:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 6BF29403A7 for ; Tue, 19 Mar 2024 19:18:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ae5-geGowGyp for ; Tue, 19 Mar 2024 19:18:35 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=148.163.155.12; helo=mx0b-002c1b01.pphosted.com; envelope-from=naveen.yerramneni@nutanix.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp4.osuosl.org 1A2364034D Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=none dis=none) header.from=nutanix.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 1A2364034D Authentication-Results: smtp4.osuosl.org; dkim=pass (2048-bit key) header.d=nutanix.com header.i=@nutanix.com header.a=rsa-sha256 header.s=proofpoint20171006 header.b=swz6ESpQ; dkim=pass (2048-bit key, unprotected) header.d=nutanix.com header.i=@nutanix.com header.a=rsa-sha256 header.s=selector1 header.b=qI2llB5U Received: from mx0b-002c1b01.pphosted.com (mx0b-002c1b01.pphosted.com [148.163.155.12]) by smtp4.osuosl.org (Postfix) with ESMTPS id 1A2364034D for ; Tue, 19 Mar 2024 19:18:34 +0000 (UTC) Received: from pps.filterd (m0127842.ppops.net [127.0.0.1]) by mx0b-002c1b01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 42JIbuHF001925; Tue, 19 Mar 2024 12:18:33 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= proofpoint20171006; bh=sqwsLdm9PETkKIR2dhyIe83UlfSvv27sv1padO1Wx vE=; b=swz6ESpQ8N/HKx2FuVN8jXZSN32D253VN2GXIQt6DiTEox+ZMQWnbBeMI 8E6ZzxmfiNO8Qq6iF4TtRrG8Zpo3OkQhFHfX9M/lR0gONcKBwk5SG/Ae6VgCXvrh CHj/gT+Okb6ZrdSE1pN0UjJgyHAZPmZ8d1In2vzByXETPjFwDkl5qSiYXQj5kCvC b02PxInMAJrNYuKZv+02hS+Hp9RqNjZf8J+eLDFVPvfq8v4G93BRzn6ODK9+ZtTl 2+w+9O0iP/yAGPb9px88Pye2R3PMv8/OMCFYo2JyvD4zUQnp0uqO1734AL4MBZbX 6NEG5OrMCXDMhOWjeXxDHfJIjvHgw== Received: from dm5pr21cu001.outbound.protection.outlook.com (mail-centralusazlp17014044.outbound.protection.outlook.com [40.93.13.44]) by mx0b-002c1b01.pphosted.com (PPS) with ESMTPS id 3wwarc6jd3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Mar 2024 12:18:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BK3Fq5YvUTPbWmbfpd6t9PaeRDrwz9PPk9x2ZtrS2Ww4ZfOnOKTBQMAmB71Ii5sdqrir2DtLOrCw494z2YzZ8Xfec3KTJKxa3wliB6112FMXFKiNQoL9oAgoHEQkuiPAV+wFkzoDxyQcZ1y7z3/jRlOWyHkuWEYcjmtohAADaMbf4XGxYt8+gAiyGJLuYNAMcOTKvCke2aggcj6I6I84hOvvAOUs4bdh2N7Zn1zx/WTUg4WWcHrcvcjKa30MNwKfocnl1osqn7if3dXtAUaDZr2neQfFIXjHnEJyVDN1QvGv2CMscFP/wFtAXS6fga+YxWuk9l0EUtNWchfhOAsIHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=sqwsLdm9PETkKIR2dhyIe83UlfSvv27sv1padO1WxvE=; b=dKX/e1UKh090V/N48mByCDwTDEHUWbnFWpVMWRdv2ENYC7akKEb1mvLxATNOl3BLZIat7vhvIy0fwGHUNk7Q4nqzaxmTQDra/07wO++4TZBCayC9kbk2JRa4nio1zEhwBB5RTkRPCuGZw2IhwHXviQVUQLQoGSU2jxyKs028l/dOmxx5vrsFOD4HRABo6tcQUVHTwJPIPNMSGLze0oL4iBmW3Iqvbs28AgOFj/k1vxq3XNk3Tm1z3K0TJNamYtg7Oes4mAeZRQqB8UpY9CdJdlCbwxIEaRh7t1TRiCym0LhKbk3hb2XJEm/jxVGL8cGvy2AbmZDzHZamfwOdrGs0fA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sqwsLdm9PETkKIR2dhyIe83UlfSvv27sv1padO1WxvE=; b=qI2llB5U41Lo/QCXLGm/twABBTX0FHYxmO9iuHkBK1EmCNuked9K6Md2cQwR6UG3M8/KFVtOEN8VlZ0ZjoitVzHQsxIXr6d2LSVP6GPXTso09djnCDZQ7Ob6xdqmgh18G7IteB8sfrfooaqI9fLKVKQVzbqc/fkwgT3sqoUWsY7rdhXZ50ONIJcbEEFGgNjAJ4ojuD3OV70WL6+XC7YBltm93NVkD0zT+N7K6rf1/+G0x689A5SOzGGvWjPALuDZJaD4wJgvmdjSqNZXSRGuo+7Cf4CrcjC/iysxViM615sppyIn87BUQTfKxO4JOn89tEAK18N4dEuiqzKHpKxcxw== Received: from SJ0PR02MB7808.namprd02.prod.outlook.com (2603:10b6:a03:326::16) by CO6PR02MB8770.namprd02.prod.outlook.com (2603:10b6:303:141::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.26; Tue, 19 Mar 2024 19:18:31 +0000 Received: from SJ0PR02MB7808.namprd02.prod.outlook.com ([fe80::d95e:4ad8:aa24:7c4]) by SJ0PR02MB7808.namprd02.prod.outlook.com ([fe80::d95e:4ad8:aa24:7c4%3]) with mapi id 15.20.7386.025; Tue, 19 Mar 2024 19:18:31 +0000 From: Naveen Yerramneni To: dev@openvswitch.org Date: Tue, 19 Mar 2024 19:17:23 +0000 Message-Id: <20240319191726.165359-2-naveen.yerramneni@nutanix.com> X-Mailer: git-send-email 2.36.6 In-Reply-To: <20240319191726.165359-1-naveen.yerramneni@nutanix.com> References: <20240319191726.165359-1-naveen.yerramneni@nutanix.com> X-ClientProxiedBy: SJ0PR03CA0097.namprd03.prod.outlook.com (2603:10b6:a03:333::12) To SJ0PR02MB7808.namprd02.prod.outlook.com (2603:10b6:a03:326::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR02MB7808:EE_|CO6PR02MB8770:EE_ X-MS-Office365-Filtering-Correlation-Id: a8d3bd47-92d3-49d3-2714-08dc48495d50 x-proofpoint-crosstenant: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3HJeUwGMhlF4KSCsn4ygPm0Yc5xwlEoydxvXB5k9b524mrCe5pjl9ri/zDEy+mJHkl6MiVWhRmP7bjnWq0LgdFEAGWFiGK0ghGucYp5AKWvRGk0RUSXG/Vh0OInQAtXLfMPuxrojlCQCEyfIcncFjsNXWfF7yBtQ/oDWy3Un3iRLj2zf8tfY9GsF895ArTgX4NdcZn/oMMChq5153tSLxefVyT88oo4jyVnICVNUZqZfxm18Xm5Ij+07kX2aw4pnHMoEupAnOW8dN9UFwRNkrGNA9csgxc+VbJNC7S7Qmnr2LTTCxe/oVas3LlYdsvcVG3ixpD5WlTnCjdyQ9o3GbcQi0GfFcKee+R0B1D49j/vfzM9kp5Mo4WNv0gbB0vUYop5AwqLvQdbUtiGuk8eHxHvCyLi6nsKmKXmyNANRKPIH69nTBah0LRA8OkHMJBiTt0HPqoOHUFZirTItobIpt54UgcIylLDujfJtXdFxw66nJh4dRtp7jCMv01di0Swb5Ve0+gk33e0/TgQa1mvS//aXf2RSB6RtmcX3QF7mmKkEhXq0dD/IsYSVh2+F3ydTn+lXx/UcS+e+wf/kP0jO8M4DsSrPAfunLOE31lbbgmgZD/6D25J3Lu5rLoU7sovHRHWvhPho/R30qibhb86X0MwS4yGV8aWVfBXkvPBn1vWGtBWb33eY/US/MyN6L3LMm/ENJLRgTBWqiVyOLMivCCbiIXKBbeun/m2qrmuukfg= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR02MB7808.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(376005)(52116005)(1800799015)(366007)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eJ8KxaFqqF5m4/43Ywbhwsz0BFMeT8999QJOcBVmktfSufD6QzJTm0PdFP1K0iYN3o7lypFJzfM+lH9Xo1JRPdPZa/v5XBclzM/sL5WTz5Qjh7SHmQzYmpQb6WnxFVBzfbP5mlQYn27hlAiPtCMtkTnZ21T+x31NOZr36RLHTFX/lJK1CRbPYVDIoBJoNs0cYNfZglczYhHYZJlztJpGhNMQyVGuZnl+18CK0vnoOO95MC33BgJ6Ls/GxszK3jrS/wzEiffqtSmo3pAXTuBRToI+SxsELAT17IyYS+HMdOfXvwd76dfn4+O8ZIrRVwkReNeIMSLZsU8esDjyQQeJurW4tv6L9/wwP1+rCKrjiWOYwIido9lE2D+6knR4tYd3hB4PhhY74062Y6DROLN/bIiCL0ShNbMWZkITQVMMPLNWs+YPtewI0FPITJlFRH94nAnMVxJkOaWmMpyq3zJIWxqHrg9v+zQ5qmjsnhtjYo9AxqVzEmwfn8eKabXm4E5hwlc5c7emsHajer8Jfw3Hi5ZPX+FcBRPYLKlreHl3zUtw984Dn0EWLgbkc3f/gVZhjhmikJpuRuqLD1SyqMWd+7Rx/hW87nKKGVWw2C5asqT+XrY4hRyD9Bhq80dpLNSfZaWuj5ol9eRHR85oIUkWseD9ezZYPGksE653qPeuFYLnqdtMXDH1q9A5iCZUETSPeVSdsFBosilVmCCmQJuFJD7jtAI0h/slGQIIK79cAMBhQAMna4C/0NPWy1LV6CTTsQ2SJARw9xoIP4+r8zI35PaJy1meX08ahgkdumG+VNy9Mv5YOqc1U+uiJ4bn8qmJ3ewUL92MYTQ2DpfecdwToikAcViQn/GVvdQlKxyJ9vVUAp6j3g6Lg+1y6Zewnnv4j+p6KzAPtE3ejIHQh7Uol9T/XIEmKm8UAycP1AW6BVQRKCbipUbDZ1utlIxRwZ5tgGyybExdg4IaAQ6RUjwj0CjX4v6fPs6CwhQ715F+/97qZzF4TMws5l0ZKQpvLr/VEvucXgfB1DMo1m5mgECWqHFvvlB7C1veg/hGIYJymLhj5+wfPuJYgK4IUqIs5Ix1vzPbKDwnIahHEVUUfiQbv2Aiicrxcos0owO4W142A/5ukBVPzyi1KMCEyUszUu6Q8w1wcDqNMeutzkP3ORLXHRaERof3H0MLSKkUMvVNd1+lyKRpa34Rjg1S+RGpj0zOonrt37qvweoEVHhKdo0wZKjGpU0SeHl2APNbgQbDtJq6UqfV2fG+hbFObfAHIQ94vPAfcdJU1bdOKHYyCmgiyCXghfJ8ZAKSzwa9T89HY1EkIbh2PQE0eaF9hYNEFyBV6z+QuajMr697urz6MdJpYXAgeUtfUAr7As8O9YeuDVN/hb18clZpLFLOHxGiRc4llIBeEkfhh+YUJtMdoaVcMoxitUWaXRGwhxEHUU8/N13UCiCQ4F3zF0bo6sw9ROrtJWnuY+B55YN5GjVmz3w8t2Sl8lZs2Af5nEbjapl+CWkL5rJkC/7vB8W4IFQdWqJsb2/vCxSeTBXhL0ZS4hBsMTcrq3HzQtEGvW/b0ytiJB57LUulXq/HTWstzpTpBAIeRz79+1Mg/PsEMrvB23rZinf8ETaiYaWsazl1TvqY30o= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: a8d3bd47-92d3-49d3-2714-08dc48495d50 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR02MB7808.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Mar 2024 19:18:31.7007 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZmS15HhR6dcdOAE0AqnWBNvsXyoNNr+dbilEeXQ6IJ3Jwr+iQiqd6fqs9h4JEx5BaAU6nBuypisU5seap73bCQpioxhtqXa5n49xIW3Wszs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR02MB8770 X-Proofpoint-GUID: 4ya9BvrEh5ebcWXfoOMGkpBe0ns0U1bG X-Proofpoint-ORIG-GUID: 4ya9BvrEh5ebcWXfoOMGkpBe0ns0U1bG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-19_08,2024-03-18_03,2023-05-22_02 X-Proofpoint-Spam-Reason: safe Cc: huzaifa.c@nutanix.com Subject: [ovs-dev] [PATCH OVN v4 1/4] actions: DHCP Relay Agent support for overlay IPv4 subnets. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" NEW OVN ACTIONS --------------- 1. dhcp_relay_req_chk(, ) - This action executes on the source node on which the DHCP request originated. - This action relays the DHCP request coming from client to the server. Relay-ip is used to update GIADDR in the DHCP header. 2. dhcp_relay_resp_chk(, ) - This action executes on the first node (RC node) which processes the DHCP response from the server. - This action updates the destination MAC and destination IP so that the response can be forwarded to the appropriate node from which request was originated. - Relay-ip, server-ip are used to validate GIADDR and SERVER ID in the DHCP payload. Signed-off-by: Naveen Yerramneni --- include/ovn/actions.h | 27 ++++++++ lib/actions.c | 149 ++++++++++++++++++++++++++++++++++++++++++ utilities/ovn-trace.c | 67 +++++++++++++++++++ 3 files changed, 243 insertions(+) diff --git a/include/ovn/actions.h b/include/ovn/actions.h index dcacbb1ff..8d0c6b9fa 100644 --- a/include/ovn/actions.h +++ b/include/ovn/actions.h @@ -96,6 +96,8 @@ struct collector_set_ids; OVNACT(LOOKUP_ND_IP, ovnact_lookup_mac_bind_ip) \ OVNACT(PUT_DHCPV4_OPTS, ovnact_put_opts) \ OVNACT(PUT_DHCPV6_OPTS, ovnact_put_opts) \ + OVNACT(DHCPV4_RELAY_REQ_CHK, ovnact_dhcp_relay) \ + OVNACT(DHCPV4_RELAY_RESP_CHK, ovnact_dhcp_relay) \ OVNACT(SET_QUEUE, ovnact_set_queue) \ OVNACT(DNS_LOOKUP, ovnact_result) \ OVNACT(LOG, ovnact_log) \ @@ -396,6 +398,15 @@ struct ovnact_put_opts { size_t n_options; }; +/* OVNACT_DHCP_RELAY. */ +struct ovnact_dhcp_relay { + struct ovnact ovnact; + int family; + struct expr_field dst; /* 1-bit destination field. */ + ovs_be32 relay_ipv4; + ovs_be32 server_ipv4; +}; + /* Valid arguments to SET_QUEUE action. * * QDISC_MIN_QUEUE_ID is the default queue, so user-defined queues should @@ -772,6 +783,22 @@ enum action_opcode { /* multicast group split buffer action. */ ACTION_OPCODE_MG_SPLIT_BUF, + + /* "dhcp_relay_req_chk(relay_ip, server_ip)". + * + * Arguments follow the action_header, in this format: + * - The 32-bit DHCP relay IP. + * - The 32-bit DHCP server IP. + */ + ACTION_OPCODE_DHCP_RELAY_REQ_CHK, + + /* "dhcp_relay_resp_chk(relay_ip, server_ip)". + * + * Arguments follow the action_header, in this format: + * - The 32-bit DHCP relay IP. + * - The 32-bit DHCP server IP. + */ + ACTION_OPCODE_DHCP_RELAY_RESP_CHK, }; /* Header. */ diff --git a/lib/actions.c b/lib/actions.c index 71615fc53..d4f4ec2d0 100644 --- a/lib/actions.c +++ b/lib/actions.c @@ -2706,6 +2706,149 @@ ovnact_controller_event_free(struct ovnact_controller_event *event) free_gen_options(event->options, event->n_options); } +static void +format_DHCPV4_RELAY_REQ_CHK(const struct ovnact_dhcp_relay *dhcp_relay, + struct ds *s) +{ + expr_field_format(&dhcp_relay->dst, s); + ds_put_format(s, " = dhcp_relay_req_chk("IP_FMT", "IP_FMT");", + IP_ARGS(dhcp_relay->relay_ipv4), + IP_ARGS(dhcp_relay->server_ipv4)); +} + +static void +parse_dhcp_relay_req_chk(struct action_context *ctx, + const struct expr_field *dst, + struct ovnact_dhcp_relay *dhcp_relay) +{ + /* Skip dhcp_relay_req_chk( */ + lexer_force_match(ctx->lexer, LEX_T_LPAREN); + + /* Validate that the destination is a 1-bit, modifiable field. */ + char *error = expr_type_check(dst, 1, true, ctx->scope); + if (error) { + lexer_error(ctx->lexer, "%s", error); + free(error); + return; + } + dhcp_relay->dst = *dst; + + /* Parse relay ip and server ip. */ + if (ctx->lexer->token.format == LEX_F_IPV4) { + dhcp_relay->family = AF_INET; + dhcp_relay->relay_ipv4 = ctx->lexer->token.value.ipv4; + lexer_get(ctx->lexer); + lexer_match(ctx->lexer, LEX_T_COMMA); + if (ctx->lexer->token.format == LEX_F_IPV4) { + dhcp_relay->family = AF_INET; + dhcp_relay->server_ipv4 = ctx->lexer->token.value.ipv4; + lexer_get(ctx->lexer); + } else { + lexer_syntax_error(ctx->lexer, "expecting IPv4 dhcp server ip"); + return; + } + } else { + lexer_syntax_error(ctx->lexer, "expecting IPv4 dhcp relay " + "and server ips"); + return; + } + lexer_force_match(ctx->lexer, LEX_T_RPAREN); +} + +static void +encode_DHCPV4_RELAY_REQ_CHK(const struct ovnact_dhcp_relay *dhcp_relay, + const struct ovnact_encode_params *ep, + struct ofpbuf *ofpacts) +{ + struct mf_subfield dst = expr_resolve_field(&dhcp_relay->dst); + size_t oc_offset = encode_start_controller_op( + ACTION_OPCODE_DHCP_RELAY_REQ_CHK, + true, ep->ctrl_meter_id, + ofpacts); + nx_put_header(ofpacts, dst.field->id, OFP15_VERSION, false); + ovs_be32 ofs = htonl(dst.ofs); + ofpbuf_put(ofpacts, &ofs, sizeof ofs); + ofpbuf_put(ofpacts, &dhcp_relay->relay_ipv4, + sizeof(dhcp_relay->relay_ipv4)); + ofpbuf_put(ofpacts, &dhcp_relay->server_ipv4, + sizeof(dhcp_relay->server_ipv4)); + encode_finish_controller_op(oc_offset, ofpacts); +} + +static void +format_DHCPV4_RELAY_RESP_CHK(const struct ovnact_dhcp_relay *dhcp_relay, + struct ds *s) +{ + expr_field_format(&dhcp_relay->dst, s); + ds_put_format(s, " = dhcp_relay_resp_chk("IP_FMT", "IP_FMT");", + IP_ARGS(dhcp_relay->relay_ipv4), + IP_ARGS(dhcp_relay->server_ipv4)); +} + +static void +parse_dhcp_relay_resp_chk(struct action_context *ctx, + const struct expr_field *dst, + struct ovnact_dhcp_relay *dhcp_relay) +{ + /* Skip dhcp_relay_resp_chk( */ + lexer_force_match(ctx->lexer, LEX_T_LPAREN); + + /* Validate that the destination is a 1-bit, modifiable field. */ + char *error = expr_type_check(dst, 1, true, ctx->scope); + if (error) { + lexer_error(ctx->lexer, "%s", error); + free(error); + return; + } + dhcp_relay->dst = *dst; + + /* Parse relay ip and server ip. */ + if (ctx->lexer->token.format == LEX_F_IPV4) { + dhcp_relay->family = AF_INET; + dhcp_relay->relay_ipv4 = ctx->lexer->token.value.ipv4; + lexer_get(ctx->lexer); + lexer_match(ctx->lexer, LEX_T_COMMA); + if (ctx->lexer->token.format == LEX_F_IPV4) { + dhcp_relay->family = AF_INET; + dhcp_relay->server_ipv4 = ctx->lexer->token.value.ipv4; + lexer_get(ctx->lexer); + } else { + lexer_syntax_error(ctx->lexer, "expecting IPv4 dhcp server ip"); + return; + } + } else { + lexer_syntax_error(ctx->lexer, "expecting IPv4 dhcp relay and " + "server ips"); + return; + } + lexer_force_match(ctx->lexer, LEX_T_RPAREN); +} + +static void +encode_DHCPV4_RELAY_RESP_CHK(const struct ovnact_dhcp_relay *dhcp_relay, + const struct ovnact_encode_params *ep, + struct ofpbuf *ofpacts) +{ + struct mf_subfield dst = expr_resolve_field(&dhcp_relay->dst); + size_t oc_offset = encode_start_controller_op( + ACTION_OPCODE_DHCP_RELAY_RESP_CHK, + true, ep->ctrl_meter_id, + ofpacts); + nx_put_header(ofpacts, dst.field->id, OFP15_VERSION, false); + ovs_be32 ofs = htonl(dst.ofs); + ofpbuf_put(ofpacts, &ofs, sizeof ofs); + ofpbuf_put(ofpacts, &dhcp_relay->relay_ipv4, + sizeof(dhcp_relay->relay_ipv4)); + ofpbuf_put(ofpacts, &dhcp_relay->server_ipv4, + sizeof(dhcp_relay->server_ipv4)); + encode_finish_controller_op(oc_offset, ofpacts); +} + +static void ovnact_dhcp_relay_free( + struct ovnact_dhcp_relay *dhcp_relay OVS_UNUSED) +{ +} + static void parse_put_opts(struct action_context *ctx, const struct expr_field *dst, struct ovnact_put_opts *po, const struct hmap *gen_opts, @@ -5406,6 +5549,12 @@ parse_set_action(struct action_context *ctx) lexer_lookahead(ctx->lexer) == LEX_T_LPAREN) { parse_chk_lb_aff(ctx, &lhs, ovnact_put_CHK_LB_AFF(ctx->ovnacts)); + } else if (lexer_match_id(ctx->lexer, "dhcp_relay_req_chk")) { + parse_dhcp_relay_req_chk(ctx, &lhs, + ovnact_put_DHCPV4_RELAY_REQ_CHK(ctx->ovnacts)); + } else if (lexer_match_id(ctx->lexer, "dhcp_relay_resp_chk")) { + parse_dhcp_relay_resp_chk(ctx, &lhs, + ovnact_put_DHCPV4_RELAY_RESP_CHK(ctx->ovnacts)); } else { parse_assignment_action(ctx, false, &lhs); } diff --git a/utilities/ovn-trace.c b/utilities/ovn-trace.c index e0f1c3ec9..dd7016fc3 100644 --- a/utilities/ovn-trace.c +++ b/utilities/ovn-trace.c @@ -2329,6 +2329,63 @@ execute_put_dhcp_opts(const struct ovnact_put_opts *pdo, execute_put_opts(pdo, name, uflow, super); } +static void +execute_dhcpv4_relay_req_chk(const struct ovnact_dhcp_relay *dr, + struct flow *uflow, struct ovs_list *super) +{ + ovntrace_node_append( + super, OVNTRACE_NODE_ERROR, + "/* We assume that this packet is DHCPDISCOVER or DHCPREQUEST. */"); + + struct ds s = DS_EMPTY_INITIALIZER; + struct mf_subfield dst = expr_resolve_field(&dr->dst); + if (!mf_is_register(dst.field->id)) { + /* Format assignment. */ + ds_clear(&s); + expr_field_format(&dr->dst, &s); + ovntrace_node_append(super, OVNTRACE_NODE_MODIFY, + "%s = 1", ds_cstr(&s)); + } + ds_destroy(&s); + + struct mf_subfield sf = expr_resolve_field(&dr->dst); + union mf_subvalue sv = { .u8_val = 1 }; + mf_write_subfield_flow(&sf, &sv, uflow); +} + +static void +execute_dhcpv4_relay_resp_chk(const struct ovnact_dhcp_relay *dr, + struct flow *uflow, struct ovs_list *super) +{ + ovntrace_node_append( + super, OVNTRACE_NODE_ERROR, + "/* We assume that this packet is DHCPOFFER or DHCPACK and " + "DHCP broadcast flag is set. Dest IP is set to broadcast. " + "Dest MAC is set to broadcast but in real network this is unicast " + "which is extracted from DHCP header. */"); + + /* Assume DHCP broadcast flag is set */ + uflow->nw_dst = htonl(0xFFFFFFFF); + /* Dest MAC is set to broadcast but in real network this is unicast */ + struct eth_addr bcast_mac = { .ea = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}}; + uflow->dl_dst = bcast_mac; + + struct ds s = DS_EMPTY_INITIALIZER; + struct mf_subfield dst = expr_resolve_field(&dr->dst); + if (!mf_is_register(dst.field->id)) { + /* Format assignment. */ + ds_clear(&s); + expr_field_format(&dr->dst, &s); + ovntrace_node_append(super, OVNTRACE_NODE_MODIFY, + "%s = 1", ds_cstr(&s)); + } + ds_destroy(&s); + + struct mf_subfield sf = expr_resolve_field(&dr->dst); + union mf_subvalue sv = { .u8_val = 1 }; + mf_write_subfield_flow(&sf, &sv, uflow); +} + static void execute_put_nd_ra_opts(const struct ovnact_put_opts *pdo, const char *name, struct flow *uflow, @@ -3216,6 +3273,16 @@ trace_actions(const struct ovnact *ovnacts, size_t ovnacts_len, "put_dhcpv6_opts", uflow, super); break; + case OVNACT_DHCPV4_RELAY_REQ_CHK: + execute_dhcpv4_relay_req_chk(ovnact_get_DHCPV4_RELAY_REQ_CHK(a), + uflow, super); + break; + + case OVNACT_DHCPV4_RELAY_RESP_CHK: + execute_dhcpv4_relay_resp_chk(ovnact_get_DHCPV4_RELAY_RESP_CHK(a), + uflow, super); + break; + case OVNACT_PUT_ND_RA_OPTS: execute_put_nd_ra_opts(ovnact_get_PUT_DHCPV6_OPTS(a), "put_nd_ra_opts", uflow, super);