diff mbox series

[ovs-dev,2/6] Track interface MTU in if-status-mgr

Message ID 20230503011239.2100488-3-ihrachys@redhat.com
State New, archived
Headers show
Series Implement MTU Path Discovery for multichassis ports | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/github-robot-_ovn-kubernetes success github build: passed

Commit Message

Ihar Hrachyshka May 3, 2023, 1:12 a.m. UTC
This will be used in a later patch to calculate the effective interface
MTU after considering tunneling overhead.

Signed-off-by: Ihar Hrachyshka <ihrachys@redhat.com>
---
 controller/binding.c   |  4 ++--
 controller/if-status.c | 31 +++++++++++++++++++++++++++----
 controller/if-status.h |  3 +++
 3 files changed, 32 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/controller/binding.c b/controller/binding.c
index 5df62baef..561b857fa 100644
--- a/controller/binding.c
+++ b/controller/binding.c
@@ -1228,7 +1228,7 @@  claim_lport(const struct sbrec_port_binding *pb,
                 }
                 set_pb_chassis_in_sbrec(pb, chassis_rec, true);
             } else {
-                if_status_mgr_claim_iface(if_mgr, pb, chassis_rec,
+                if_status_mgr_claim_iface(if_mgr, pb, chassis_rec, iface_rec,
                                           sb_readonly);
             }
             register_claim_timestamp(pb->logical_port, now);
@@ -1241,7 +1241,7 @@  claim_lport(const struct sbrec_port_binding *pb,
             } else {
                 if (pb->n_up && !pb->up[0]) {
                     if_status_mgr_claim_iface(if_mgr, pb, chassis_rec,
-                                              sb_readonly);
+                                              iface_rec, sb_readonly);
                 }
             }
         }
diff --git a/controller/if-status.c b/controller/if-status.c
index d1c14ac30..f2ea21635 100644
--- a/controller/if-status.c
+++ b/controller/if-status.c
@@ -24,6 +24,7 @@ 
 #include "lib/util.h"
 #include "timeval.h"
 #include "openvswitch/vlog.h"
+#include "lib/vswitch-idl.h"
 #include "lib/ovn-sb-idl.h"
 
 VLOG_DEFINE_THIS_MODULE(if_status);
@@ -146,6 +147,7 @@  struct ovs_iface {
                              * be fully programmed in OVS.  Only used in state
                              * OIF_INSTALL_FLOWS.
                              */
+    uint16_t mtu;           /* Extracted from OVS interface.mtu field. */
 };
 
 static uint64_t ifaces_usage;
@@ -167,9 +169,10 @@  struct if_status_mgr {
     uint32_t iface_seqno;
 };
 
-static struct ovs_iface *ovs_iface_create(struct if_status_mgr *,
-                                          const char *iface_id,
-                                          enum if_state );
+static struct ovs_iface *
+ovs_iface_create(struct if_status_mgr *, const char *iface_id,
+                 const struct ovsrec_interface *iface_rec,
+                 enum if_state);
 static void ovs_iface_destroy(struct if_status_mgr *, struct ovs_iface *);
 static void ovs_iface_set_state(struct if_status_mgr *, struct ovs_iface *,
                                 enum if_state);
@@ -222,13 +225,14 @@  void
 if_status_mgr_claim_iface(struct if_status_mgr *mgr,
                           const struct sbrec_port_binding *pb,
                           const struct sbrec_chassis *chassis_rec,
+                          const struct ovsrec_interface *iface_rec,
                           bool sb_readonly)
 {
     const char *iface_id = pb->logical_port;
     struct ovs_iface *iface = shash_find_data(&mgr->ifaces, iface_id);
 
     if (!iface) {
-        iface = ovs_iface_create(mgr, iface_id, OIF_CLAIMED);
+        iface = ovs_iface_create(mgr, iface_id, iface_rec, OIF_CLAIMED);
     }
 
     if (!sb_readonly) {
@@ -492,14 +496,33 @@  ovs_iface_account_mem(const char *iface_id, bool erase)
     }
 }
 
+static uint16_t
+get_iface_mtu(const struct ovsrec_interface *iface)
+{
+    if (!iface || !iface->n_mtu || iface->mtu[0] <= 0) {
+        return 0;
+    }
+    return (uint16_t) iface->mtu[0];
+}
+
+uint16_t
+if_status_mgr_iface_get_mtu(const struct if_status_mgr *mgr,
+                            const char *iface_id)
+{
+    const struct ovs_iface *iface = shash_find_data(&mgr->ifaces, iface_id);
+    return iface ? iface->mtu : 0;
+}
+
 static struct ovs_iface *
 ovs_iface_create(struct if_status_mgr *mgr, const char *iface_id,
+                 const struct ovsrec_interface *iface_rec,
                  enum if_state state)
 {
     struct ovs_iface *iface = xzalloc(sizeof *iface);
 
     VLOG_DBG("Interface %s create.", iface_id);
     iface->id = xstrdup(iface_id);
+    iface->mtu = get_iface_mtu(iface_rec);
     shash_add_nocopy(&mgr->ifaces, iface->id, iface);
     ovs_iface_set_state(mgr, iface, state);
     ovs_iface_account_mem(iface_id, false);
diff --git a/controller/if-status.h b/controller/if-status.h
index 5bd187a25..ab1625b18 100644
--- a/controller/if-status.h
+++ b/controller/if-status.h
@@ -29,6 +29,7 @@  void if_status_mgr_destroy(struct if_status_mgr *);
 void if_status_mgr_claim_iface(struct if_status_mgr *,
                                const struct sbrec_port_binding *pb,
                                const struct sbrec_chassis *chassis_rec,
+                               const struct ovsrec_interface *iface_rec,
                                bool sb_readonly);
 void if_status_mgr_release_iface(struct if_status_mgr *, const char *iface_id);
 void if_status_mgr_delete_iface(struct if_status_mgr *, const char *iface_id);
@@ -48,5 +49,7 @@  bool if_status_handle_claims(struct if_status_mgr *mgr,
                              const struct sbrec_chassis *chassis_rec,
                              struct hmap *tracked_datapath,
                              bool sb_readonly);
+uint16_t if_status_mgr_iface_get_mtu(const struct if_status_mgr *mgr,
+                                     const char *iface_id);
 
 # endif /* controller/if-status.h */