From e8be37613784c96c48c18e23790c7c246d2c750b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 17 Apr 2014 11:15:36 +0200 Subject: [PATCH 1/1] core: fix MTU handling while merging/subtracting IP configs (bgo #721420) https://bugzilla.gnome.org/show_bug.cgi?id=721420 https://bugzilla.redhat.com/show_bug.cgi?id=1047083 (cherry picked from commit 0757e33e746f0a203b4a4c5f386307e3a8ed9766) Conflicts: src/tests/test-ip4-config.c --- src/nm-ip4-config.c | 12 ++++++++++- src/tests/test-ip4-config.c | 50 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index b7ae161..23be6d7 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -15,7 +15,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright (C) 2005 - 2013 Red Hat, Inc. + * Copyright (C) 2005 - 2014 Red Hat, Inc. * Copyright (C) 2006 - 2008 Novell, Inc. */ @@ -386,9 +386,14 @@ nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src) for (i = 0; i < nm_ip4_config_get_num_searches (src); i++) nm_ip4_config_add_search (dst, nm_ip4_config_get_search (src, i)); + /* MSS */ if (!nm_ip4_config_get_mss (dst)) nm_ip4_config_set_mss (dst, nm_ip4_config_get_mss (src)); + /* MTU */ + if (!nm_ip4_config_get_mtu (dst)) + nm_ip4_config_set_mtu (dst, nm_ip4_config_get_mtu (src)); + /* NIS */ for (i = 0; i < nm_ip4_config_get_num_nis_servers (src); i++) nm_ip4_config_add_nis_server (dst, nm_ip4_config_get_nis_server (src, i)); @@ -495,9 +500,14 @@ nm_ip4_config_subtract (NMIP4Config *dst, const NMIP4Config *src) } } + /* MSS */ if (nm_ip4_config_get_mss (src) == nm_ip4_config_get_mss (dst)) nm_ip4_config_set_mss (dst, 0); + /* MTU */ + if (nm_ip4_config_get_mtu (src) == nm_ip4_config_get_mtu (dst)) + nm_ip4_config_set_mtu (dst, 0); + /* NIS */ for (i = 0; i < nm_ip4_config_get_num_nis_servers (src); i++) { guint32 src_nis = nm_ip4_config_get_nis_server (src, i); diff --git a/src/tests/test-ip4-config.c b/src/tests/test-ip4-config.c index fde4a40..1f2c968 100644 --- a/src/tests/test-ip4-config.c +++ b/src/tests/test-ip4-config.c @@ -14,7 +14,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright (C) 2013 Red Hat, Inc. + * Copyright (C) 2013 - 2014 Red Hat, Inc. * */ @@ -116,6 +116,8 @@ test_subtract (void) const char *expected_search = "somewhere.com"; guint32 expected_nis = addr_to_num ("1.2.3.13"); guint32 expected_wins = addr_to_num ("2.3.4.5"); + guint32 expected_mss = 1400; + guint32 expected_mtu = 1492; src = build_test_config (); @@ -135,6 +137,9 @@ test_subtract (void) nm_ip4_config_add_nis_server (dst, expected_nis); nm_ip4_config_add_wins (dst, expected_wins); + nm_ip4_config_set_mss (dst, expected_mss); + nm_ip4_config_set_mtu (dst, expected_mtu); + nm_ip4_config_subtract (dst, src); /* ensure what's left is what we expect */ @@ -169,10 +174,52 @@ test_subtract (void) g_assert_cmpuint (nm_ip4_config_get_num_wins (dst), ==, 1); g_assert_cmpuint (nm_ip4_config_get_wins (dst, 0), ==, expected_wins); + g_assert_cmpuint (nm_ip4_config_get_mss (dst), ==, expected_mss); + g_assert_cmpuint (nm_ip4_config_get_mtu (dst), ==, expected_mtu); + g_object_unref (src); g_object_unref (dst); } +static void +test_merge_subtract_mss_mtu (void) +{ + NMIP4Config *cfg1, *cfg2, *cfg3; + guint32 expected_mss2 = 1400; + guint32 expected_mtu2 = 1492; + guint32 expected_mss3 = 555; + guint32 expected_mtu3 = 666; + + cfg1 = build_test_config (); + cfg2 = build_test_config (); + cfg3 = build_test_config (); + + /* add MSS, MTU to configs to test them */ + nm_ip4_config_set_mss (cfg2, expected_mss2); + nm_ip4_config_set_mtu (cfg2, expected_mtu2); + nm_ip4_config_set_mss (cfg3, expected_mss3); + nm_ip4_config_set_mtu (cfg3, expected_mtu3); + + nm_ip4_config_merge (cfg1, cfg2); + /* ensure MSS and MTU are in cfg1 */ + g_assert_cmpuint (nm_ip4_config_get_mss (cfg1), ==, expected_mss2); + g_assert_cmpuint (nm_ip4_config_get_mtu (cfg1), ==, expected_mtu2); + + nm_ip4_config_merge (cfg1, cfg3); + /* ensure again the same MSS and MTU are in cfg1 */ + g_assert_cmpuint (nm_ip4_config_get_mss (cfg1), ==, expected_mss2); + g_assert_cmpuint (nm_ip4_config_get_mtu (cfg1), ==, expected_mtu2); + + nm_ip4_config_subtract (cfg1, cfg2); + /* ensure MSS and MTU are zero in cfg1 */ + g_assert_cmpuint (nm_ip4_config_get_mss (cfg1), ==, 0); + g_assert_cmpuint (nm_ip4_config_get_mtu (cfg1), ==, 0); + + g_object_unref (cfg1); + g_object_unref (cfg2); + g_object_unref (cfg3); +} + /*******************************************/ int @@ -183,6 +230,7 @@ main (int argc, char **argv) g_type_init (); g_test_add_func ("/ip4-config/subtract", test_subtract); + g_test_add_func ("/ip4-config/merge-subtract-mss-mtu", test_merge_subtract_mss_mtu); return g_test_run (); } -- 1.9.3