From 711f69fb738a253674149eb302108dc688181190 Mon Sep 17 00:00:00 2001 From: Ana Cabral Date: Mon, 15 Aug 2022 18:18:45 -0300 Subject: release: bump version to 1.41.0 (development) --- configure.ac | 4 ++-- meson.build | 2 +- po/as.po | 2 +- po/be@latin.po | 2 +- po/bg.po | 2 +- po/bn_IN.po | 2 +- po/bs.po | 2 +- po/ca.po | 2 +- po/cs.po | 2 +- po/da.po | 2 +- po/de.po | 2 +- po/dz.po | 2 +- po/el.po | 2 +- po/en_CA.po | 2 +- po/en_GB.po | 2 +- po/eo.po | 2 +- po/es.po | 2 +- po/et.po | 2 +- po/eu.po | 2 +- po/fi.po | 2 +- po/fr.po | 2 +- po/gd.po | 2 +- po/gl.po | 2 +- po/gu.po | 2 +- po/he.po | 2 +- po/hi.po | 2 +- po/hr.po | 2 +- po/hu.po | 2 +- po/id.po | 2 +- po/it.po | 2 +- po/ja.po | 2 +- po/ka.po | 2 +- po/kn.po | 2 +- po/ko.po | 2 +- po/ku.po | 2 +- po/lt.po | 2 +- po/lv.po | 2 +- po/mk.po | 2 +- po/ml.po | 2 +- po/mr.po | 2 +- po/nb.po | 2 +- po/ne.po | 2 +- po/nl.po | 2 +- po/oc.po | 2 +- po/or.po | 2 +- po/pa.po | 2 +- po/pl.po | 2 +- po/pt.po | 2 +- po/pt_BR.po | 2 +- po/ro.po | 2 +- po/ru.po | 2 +- po/rw.po | 2 +- po/sk.po | 2 +- po/sl.po | 2 +- po/sq.po | 2 +- po/sr.po | 2 +- po/sr@latin.po | 2 +- po/sv.po | 2 +- po/ta.po | 2 +- po/te.po | 2 +- po/th.po | 2 +- po/tr.po | 2 +- po/uk.po | 2 +- po/vi.po | 2 +- po/wa.po | 2 +- po/zh_CN.po | 2 +- po/zh_HK.po | 2 +- po/zh_TW.po | 2 +- 68 files changed, 69 insertions(+), 69 deletions(-) diff --git a/configure.ac b/configure.ac index 3bf272618e..2279c9d11c 100644 --- a/configure.ac +++ b/configure.ac @@ -7,8 +7,8 @@ dnl - add corresponding NM_VERSION_x_y_z macros in dnl "shared/nm-version-macros.h.in" dnl - update number in meson.build m4_define([nm_major_version], [1]) -m4_define([nm_minor_version], [39]) -m4_define([nm_micro_version], [90]) +m4_define([nm_minor_version], [41]) +m4_define([nm_micro_version], [0]) m4_define([nm_version], [nm_major_version.nm_minor_version.nm_micro_version]) diff --git a/meson.build b/meson.build index 300e71319c..faf47f58f8 100644 --- a/meson.build +++ b/meson.build @@ -6,7 +6,7 @@ project( # - add corresponding NM_VERSION_x_y_z macros in # "src/libnm-core-public/nm-version-macros.h.in" # - update number in configure.ac - version: '1.39.90', + version: '1.41.0', license: 'GPL2+', default_options: [ 'buildtype=debugoptimized', diff --git a/po/as.po b/po/as.po index ad3c91797d..db92a5fa06 100644 --- a/po/as.po +++ b/po/as.po @@ -10,7 +10,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:06-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Assamese \n" diff --git a/po/be@latin.po b/po/be@latin.po index 35afe9f8f9..f4a1f2e523 100644 --- a/po/be@latin.po +++ b/po/be@latin.po @@ -3,7 +3,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2008-03-29 21:43+0200\n" "Last-Translator: Ihar Hrachyshka \n" "Language-Team: Belarusian Latin \n" diff --git a/po/bg.po b/po/bg.po index 94fd8cff8e..7d5a118429 100644 --- a/po/bg.po +++ b/po/bg.po @@ -11,7 +11,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:07-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Bulgarian \n" diff --git a/po/bn_IN.po b/po/bn_IN.po index a30d967f65..1b9956d57b 100644 --- a/po/bn_IN.po +++ b/po/bn_IN.po @@ -12,7 +12,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:09-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Bengali (India) \n" diff --git a/po/bs.po b/po/bs.po index 52e6a12817..e06ec92612 100644 --- a/po/bs.po +++ b/po/bs.po @@ -9,7 +9,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 06:12-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Bosnian \n" diff --git a/po/ca.po b/po/ca.po index e9c835e152..a82b61db2d 100644 --- a/po/ca.po +++ b/po/ca.po @@ -14,7 +14,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:12-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Catalan \n" diff --git a/po/cs.po b/po/cs.po index 2c5834d453..8c24df2c36 100644 --- a/po/cs.po +++ b/po/cs.po @@ -17,7 +17,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2018-09-30 14:02+0200\n" "Last-Translator: Daniel Rusek \n" "Language-Team: Czech \n" diff --git a/po/da.po b/po/da.po index 9cb8c4a099..bd1aba6417 100644 --- a/po/da.po +++ b/po/da.po @@ -13,7 +13,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2020-12-30 00:00+0200\n" "Last-Translator: scootergrisen\n" "Language-Team: Danish\n" diff --git a/po/de.po b/po/de.po index f42709057d..a8e9e529b9 100644 --- a/po/de.po +++ b/po/de.po @@ -24,7 +24,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2018-07-15 17:31+0200\n" "Last-Translator: Mario Blättermann \n" "Language-Team: Deutsch \n" diff --git a/po/dz.po b/po/dz.po index 6cc550b5b3..a78619c030 100644 --- a/po/dz.po +++ b/po/dz.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2007-03-20 10:17+0530\n" "Last-Translator: sonam pelden \n" "Language-Team: Dzongkha \n" diff --git a/po/el.po b/po/el.po index 4702122fc3..cb3f803f6a 100644 --- a/po/el.po +++ b/po/el.po @@ -15,7 +15,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-05-29 11:19-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: team@lists.gnome.gr\n" diff --git a/po/en_CA.po b/po/en_CA.po index dba24013fe..8595a9a4fe 100644 --- a/po/en_CA.po +++ b/po/en_CA.po @@ -9,7 +9,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2005-09-06 14:52-0400\n" "Last-Translator: Adam Weinberger \n" "Language-Team: Canadian English \n" diff --git a/po/en_GB.po b/po/en_GB.po index 6a17cba661..480c4cbe4e 100644 --- a/po/en_GB.po +++ b/po/en_GB.po @@ -12,7 +12,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:17-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Sugar Labs\n" diff --git a/po/eo.po b/po/eo.po index 6fd82e1995..8c5d3d62ea 100644 --- a/po/eo.po +++ b/po/eo.po @@ -14,7 +14,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2020-01-12 14:16+0100\n" "Last-Translator: Carmen Bianca BAKKER \n" "Language-Team: Esperanto \n" diff --git a/po/es.po b/po/es.po index 5875c044bf..a17de8f6a4 100644 --- a/po/es.po +++ b/po/es.po @@ -24,7 +24,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2019-05-03 09:09+0200\n" "Last-Translator: Daniel Mustieles \n" "Language-Team: es \n" diff --git a/po/et.po b/po/et.po index d583336a86..ba2e3aaf00 100644 --- a/po/et.po +++ b/po/et.po @@ -15,7 +15,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 06:05-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Estonian \n" diff --git a/po/eu.po b/po/eu.po index 7045bd6b8a..7bf9b9bd08 100644 --- a/po/eu.po +++ b/po/eu.po @@ -10,7 +10,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 06:06-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Basque \n" diff --git a/po/fi.po b/po/fi.po index dd9c49fbae..71aae9ca8a 100644 --- a/po/fi.po +++ b/po/fi.po @@ -14,7 +14,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:18-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Finnish \n" diff --git a/po/fr.po b/po/fr.po index db704f57ff..a32218b172 100644 --- a/po/fr.po +++ b/po/fr.po @@ -16,7 +16,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2019-08-15 10:06+0000\n" "Last-Translator: ljanda \n" "Language-Team: French \n" diff --git a/po/gd.po b/po/gd.po index c4bc3cb20e..214895ba12 100644 --- a/po/gd.po +++ b/po/gd.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2016-01-29 11:29+0100\n" "Last-Translator: GunChleoc \n" "Language-Team: Fòram na Gàidhlig\n" diff --git a/po/gl.po b/po/gl.po index aebf7f95bf..c5dc8419a1 100644 --- a/po/gl.po +++ b/po/gl.po @@ -12,7 +12,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 06:08-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: gnome-l10n-gl@gnome.org\n" diff --git a/po/gu.po b/po/gu.po index 911c35e19e..6ce2d6afbf 100644 --- a/po/gu.po +++ b/po/gu.po @@ -14,7 +14,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:23-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: American English \n" diff --git a/po/he.po b/po/he.po index e9c6ed783e..eac04676c8 100644 --- a/po/he.po +++ b/po/he.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2016-04-16 05:26-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: he\n" diff --git a/po/hi.po b/po/hi.po index 18233e4d89..95d5745fb4 100644 --- a/po/hi.po +++ b/po/hi.po @@ -12,7 +12,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:25-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Hindi \n" diff --git a/po/hr.po b/po/hr.po index 52d41a9211..d34c50f446 100644 --- a/po/hr.po +++ b/po/hr.po @@ -11,7 +11,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2022-03-31 20:12+0200\n" "Last-Translator: gogo \n" "Language-Team: Croatian \n" diff --git a/po/hu.po b/po/hu.po index 178594714c..42deb0e16b 100644 --- a/po/hu.po +++ b/po/hu.po @@ -12,7 +12,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:27-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Hungarian \n" diff --git a/po/id.po b/po/id.po index 996e1d6b19..73ac190d35 100644 --- a/po/id.po +++ b/po/id.po @@ -10,7 +10,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2019-12-31 15:54+0700\n" "Last-Translator: Andika Triwidada \n" "Language-Team: GNOME Indonesian Translation Team \n" diff --git a/po/it.po b/po/it.po index b8ce357e72..55aa6c7ba6 100644 --- a/po/it.po +++ b/po/it.po @@ -12,7 +12,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2019-03-21 14:53+0100\n" "Last-Translator: Milo Casagrande \n" "Language-Team: Italian \n" diff --git a/po/ja.po b/po/ja.po index 6f08e99115..983491cfb7 100644 --- a/po/ja.po +++ b/po/ja.po @@ -12,7 +12,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2019-08-15 04:44+0000\n" "Last-Translator: kemorigu \n" "Language-Team: Japanese \n" diff --git a/po/ka.po b/po/ka.po index d75b2036da..4ceaf5a912 100644 --- a/po/ka.po +++ b/po/ka.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2022-07-16 18:47+0200\n" "Last-Translator: Temuri Doghonadze \n" "Language-Team: Georgian \n" "Language-Team: Kannada \n" diff --git a/po/ko.po b/po/ko.po index 7465656d18..44a5b50bbf 100644 --- a/po/ko.po +++ b/po/ko.po @@ -33,7 +33,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2020-08-23 16:31+0900\n" "Last-Translator: Changwoo Ryu \n" "Language-Team: GNOME Korea \n" diff --git a/po/ku.po b/po/ku.po index d7de131422..dc6766f453 100644 --- a/po/ku.po +++ b/po/ku.po @@ -9,7 +9,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2007-01-02 21:47+0000\n" "Last-Translator: Erdal Ronahi \n" "Language-Team: Kurdish \n" diff --git a/po/lt.po b/po/lt.po index bacbd2d0d6..9f1058673e 100644 --- a/po/lt.po +++ b/po/lt.po @@ -13,7 +13,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 06:10-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Lietuvių \n" diff --git a/po/lv.po b/po/lv.po index f07cc15e6b..2bfd5be141 100644 --- a/po/lv.po +++ b/po/lv.po @@ -10,7 +10,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:39-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Latvian \n" diff --git a/po/mk.po b/po/mk.po index a7e19b4d7a..71cd4ad9de 100644 --- a/po/mk.po +++ b/po/mk.po @@ -13,7 +13,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2016-04-16 12:56-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Macedonian \n" diff --git a/po/ml.po b/po/ml.po index 359dd84fac..ca052dfe86 100644 --- a/po/ml.po +++ b/po/ml.po @@ -12,7 +12,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:41-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Malayalam \n" diff --git a/po/mr.po b/po/mr.po index 1499f75757..09559493b9 100644 --- a/po/mr.po +++ b/po/mr.po @@ -10,7 +10,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:43-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Marathi \n" diff --git a/po/nb.po b/po/nb.po index fe42dd07e2..23e2ca8419 100644 --- a/po/nb.po +++ b/po/nb.po @@ -10,7 +10,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:43-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Norwegian Bokmål \n" diff --git a/po/ne.po b/po/ne.po index acd4f1b9e5..641faadea1 100644 --- a/po/ne.po +++ b/po/ne.po @@ -13,7 +13,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 06:26-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Nepali \n" diff --git a/po/nl.po b/po/nl.po index 49cfc4e284..9c4e2b5ed3 100644 --- a/po/nl.po +++ b/po/nl.po @@ -19,7 +19,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2022-03-27 21:08+0200\n" "Last-Translator: Nathan Follens \n" "Language-Team: Dutch \n" diff --git a/po/oc.po b/po/oc.po index 7e548c1be0..379989584e 100644 --- a/po/oc.po +++ b/po/oc.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2021-05-18 21:37+0200\n" "Last-Translator: Quentin PAGÈS\n" "Language-Team: Tot en òc (totenoc.eu)\n" diff --git a/po/or.po b/po/or.po index bff59077fe..509836e909 100644 --- a/po/or.po +++ b/po/or.po @@ -10,7 +10,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:45-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Oriya \n" diff --git a/po/pa.po b/po/pa.po index d7955b43e0..0791d65837 100644 --- a/po/pa.po +++ b/po/pa.po @@ -13,7 +13,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2019-04-19 10:17-0500\n" "Last-Translator: A S Alam \n" "Language-Team: Punjabi \n" diff --git a/po/pl.po b/po/pl.po index e6aa2bc55c..861b57d09b 100644 --- a/po/pl.po +++ b/po/pl.po @@ -12,7 +12,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2020-04-12 11:20+0200\n" "Last-Translator: Piotr Drąg \n" "Language-Team: Polish \n" diff --git a/po/pt.po b/po/pt.po index cd02527bae..9c00362ccc 100644 --- a/po/pt.po +++ b/po/pt.po @@ -9,7 +9,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2020-10-11 21:09+0100\n" "Last-Translator: Juliano de Souza Camargo \n" "Language-Team: Portuguese < >\n" diff --git a/po/pt_BR.po b/po/pt_BR.po index effec72c27..f5e525fa2d 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -21,7 +21,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2020-03-10 04:12-0300\n" "Last-Translator: Rafael Fontenelle \n" "Language-Team: Brazilian Portuguese \n" diff --git a/po/ro.po b/po/ro.po index 02a9ca2ebc..33b2dc7e3b 100644 --- a/po/ro.po +++ b/po/ro.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2022-03-14 13:23+0000\n" "Last-Translator: Sergiu Bivol \n" "Language-Team: Romanian \n" diff --git a/po/ru.po b/po/ru.po index 733b899aff..b70eead4ed 100644 --- a/po/ru.po +++ b/po/ru.po @@ -21,7 +21,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2021-03-31 20:27+0300\n" "Last-Translator: Дронова Ю \n" "Language-Team: Russian \n" diff --git a/po/rw.po b/po/rw.po index 60c456e815..eb597cf164 100644 --- a/po/rw.po +++ b/po/rw.po @@ -16,7 +16,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2005-03-31 20:55-0700\n" "Last-Translator: Steve Murphy \n" "Language-Team: Kinyarwanda \n" diff --git a/po/sk.po b/po/sk.po index d3ef93317f..4b8eed3a11 100644 --- a/po/sk.po +++ b/po/sk.po @@ -12,7 +12,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2019-05-15 16:46+0200\n" "Last-Translator: Jose Riha \n" "Language-Team: Slovak \n" diff --git a/po/sl.po b/po/sl.po index 233333a535..0b471c41d2 100644 --- a/po/sl.po +++ b/po/sl.po @@ -12,7 +12,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 06:11-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Slovenian GNOME Translation Team \n" diff --git a/po/sq.po b/po/sq.po index 253f1c79cc..7e6af58ed2 100644 --- a/po/sq.po +++ b/po/sq.po @@ -9,7 +9,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 06:11-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Albanian \n" diff --git a/po/sr.po b/po/sr.po index 18d7c714ed..120ae71425 100644 --- a/po/sr.po +++ b/po/sr.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2010-10-18 16:48+0200\n" "Last-Translator: Милош Поповић \n" "Language-Team: Serbian \n" diff --git a/po/sr@latin.po b/po/sr@latin.po index 9d582837d7..25fe899cae 100644 --- a/po/sr@latin.po +++ b/po/sr@latin.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2010-10-18 16:48+0200\n" "Last-Translator: Miloš Popović \n" "Language-Team: Serbian \n" diff --git a/po/sv.po b/po/sv.po index eae5971605..22200fbcba 100644 --- a/po/sv.po +++ b/po/sv.po @@ -9,7 +9,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-12-04 20:16+0100\n" "Last-Translator: Josef Andersson \n" "Language-Team: Swedish \n" diff --git a/po/ta.po b/po/ta.po index ecbbbce9b8..73ba34abf4 100644 --- a/po/ta.po +++ b/po/ta.po @@ -14,7 +14,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 06:21-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Tamil \n" diff --git a/po/te.po b/po/te.po index b5cd7a0c3b..9ed1b982b6 100644 --- a/po/te.po +++ b/po/te.po @@ -11,7 +11,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:58-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Telugu \n" diff --git a/po/th.po b/po/th.po index 40ddd573ed..9c7c00397d 100644 --- a/po/th.po +++ b/po/th.po @@ -10,7 +10,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 05:59-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Thai \n" diff --git a/po/tr.po b/po/tr.po index 71b768a71a..1b5a424c35 100644 --- a/po/tr.po +++ b/po/tr.po @@ -12,7 +12,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 06:01-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Türkçe \n" diff --git a/po/uk.po b/po/uk.po index ad03dd5e4b..addf706b60 100644 --- a/po/uk.po +++ b/po/uk.po @@ -10,7 +10,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2022-07-03 08:50+0300\n" "Last-Translator: Yuri Chornoivan \n" "Language-Team: Ukrainian \n" diff --git a/po/vi.po b/po/vi.po index 56a8bd7077..3654e41b5f 100644 --- a/po/vi.po +++ b/po/vi.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 06:11-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Vietnamese \n" diff --git a/po/wa.po b/po/wa.po index 23963fb7c9..cafb5380a2 100644 --- a/po/wa.po +++ b/po/wa.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2004-09-09 10:41+0200\n" "Last-Translator: Pablo Saratxaga \n" "Language-Team: Walloon \n" diff --git a/po/zh_CN.po b/po/zh_CN.po index 536abd0a0e..c06535a1dd 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -20,7 +20,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2021-11-09 20:06+0800\n" "Last-Translator: Dingzhong Chen \n" "Language-Team: Chinese - China \n" diff --git a/po/zh_HK.po b/po/zh_HK.po index b01f7d65cb..6d0c45caf0 100644 --- a/po/zh_HK.po +++ b/po/zh_HK.po @@ -9,7 +9,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2017-04-21 06:26-0400\n" "Last-Translator: Copied by Zanata \n" "Language-Team: Chinese (Hong Kong) \n" diff --git a/po/zh_TW.po b/po/zh_TW.po index 2b56f90db3..8934e760e3 100644 --- a/po/zh_TW.po +++ b/po/zh_TW.po @@ -20,7 +20,7 @@ msgstr "" "Project-Id-Version: NetworkManager\n" "Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/NetworkManager/" "NetworkManager/issues\n" -"POT-Creation-Date: 2022-08-11 16:06-0300\n" +"POT-Creation-Date: 2022-08-15 18:14-0300\n" "PO-Revision-Date: 2019-06-28 19:18+0800\n" "Last-Translator: Hsiu-Ming Chang \n" "Language-Team: Traditional Chinese \n" -- cgit v1.2.1 From 0e26203e02969ce6e4475ea3bb2acfcdafed1a37 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 23 Aug 2022 14:02:52 +0200 Subject: libnm: reword documentation for "ipv4.gateway" and "ipv6.gateway" --- src/libnm-core-impl/nm-setting-ip-config.c | 12 +++++++----- src/libnmc-setting/settings-docs.h.in | 4 ++-- src/nmcli/generate-docs-nm-settings-nmcli.xml.in | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index ab760c4e5f..916a803806 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -6304,12 +6304,14 @@ nm_setting_ip_config_class_init(NMSettingIPConfigClass *klass) * The gateway associated with this configuration. This is only meaningful * if #NMSettingIPConfig:addresses is also set. * - * The gateway's main purpose is to control the next hop of the standard default route on the device. - * Hence, the gateway property conflicts with #NMSettingIPConfig:never-default and will be - * automatically dropped if the IP configuration is set to never-default. + * Setting the gateway causes NetworkManager to configure a standard default route + * with the gateway as next hop. This is ignored if #NMSettingIPConfig:never-default + * is set. An alternative is to configure the default route explicitly with a manual + * route and /0 as prefix length. * - * As an alternative to set the gateway, configure a static default route with /0 as prefix - * length. + * Note that the gateway usually conflicts with routing that NetworkManager configures + * for WireGuard interfaces, so usually it should not be set in that case. See + * #NMSettingWireGuard:ip4-auto-default-route. **/ obj_properties[PROP_GATEWAY] = g_param_spec_string( NM_SETTING_IP_CONFIG_GATEWAY, diff --git a/src/libnmc-setting/settings-docs.h.in b/src/libnmc-setting/settings-docs.h.in index 3e86c04b11..2a2ec2eea2 100644 --- a/src/libnmc-setting/settings-docs.h.in +++ b/src/libnmc-setting/settings-docs.h.in @@ -171,7 +171,7 @@ #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_OPTIONS N_("Array of DNS options as described in man 5 resolv.conf. NULL means that the options are unset and left at the default. In this case NetworkManager will use default options. This is distinct from an empty list of properties. The currently supported options are \"attempts\", \"debug\", \"edns0\", \"inet6\", \"ip6-bytestring\", \"ip6-dotint\", \"ndots\", \"no-check-names\", \"no-ip6-dotint\", \"no-reload\", \"no-tld-query\", \"rotate\", \"single-request\", \"single-request-reopen\", \"timeout\", \"trust-ad\", \"use-vc\". The \"trust-ad\" setting is only honored if the profile contributes name servers to resolv.conf, and if all contributing profiles have \"trust-ad\" enabled. When using a caching DNS plugin (dnsmasq or systemd-resolved in NetworkManager.conf) then \"edns0\" and \"trust-ad\" are automatically added.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower numerical value is better (higher priority). Negative values have the special effect of excluding other configurations with a greater numerical priority value; so in presence of at least one negative priority, only DNS servers from connections with the lowest priority value will be used. To avoid all DNS leaks, set the priority of the profile that should be used to the most negative value of all active connections profiles. Zero selects a globally configured default value. If the latter is missing or zero too, it defaults to 50 for VPNs (including WireGuard) and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When multiple devices have configurations with the same priority, VPNs will be considered first, then devices with the best (lowest metric) default route and then all other devices. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. Note that commonly the resolver tries name servers in /etc/resolv.conf in the order listed, proceeding with the next server in the list on failure. See for example the \"rotate\" option of the dns-options setting. If there are any negative DNS priorities, then only name servers from the devices with that lowest priority will be considered. When using a DNS resolver that supports Conditional Forwarding or Split DNS (with dns=dnsmasq or dns=systemd-resolved settings), each connection is used to query domains in its search list. The search domains determine which name servers to ask, and the DNS priority is used to prioritize name servers based on the domain. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the best priority (lowest numerical value) wins. If a sub domain is configured on another interface it will be accepted regardless the priority, unless parent domain on the other interface has a negative priority, which causes the sub domain to be shadowed. With Split DNS one can avoid undesired DNS leaks by properly configuring DNS priorities and the search domains, so that only name servers of the desired interface are configured.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_SEARCH N_("List of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names. When using a DNS plugin that supports Conditional Forwarding or Split DNS, then the search domains specify which name servers to query. This makes the behavior different from running with plain /etc/resolv.conf. For more information see also the dns-priority setting. When set on a profile that also enabled DHCP, the DNS search list received automatically (option 119 for DHCPv4 and option 24 for DHCPv6) gets merged with the manual list. This can be prevented by setting \"ignore-auto-dns\". Note that if no DNS searches are configured, the fallback will be derived from the domain from DHCP (option 15).") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_GATEWAY N_("The gateway associated with this configuration. This is only meaningful if \"addresses\" is also set. The gateway's main purpose is to control the next hop of the standard default route on the device. Hence, the gateway property conflicts with \"never-default\" and will be automatically dropped if the IP configuration is set to never-default. As an alternative to set the gateway, configure a static default route with /0 as prefix length.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_GATEWAY N_("The gateway associated with this configuration. This is only meaningful if \"addresses\" is also set. Setting the gateway causes NetworkManager to configure a standard default route with the gateway as next hop. This is ignored if \"never-default\" is set. An alternative is to configure the default route explicitly with a manual route and /0 as prefix length. Note that the gateway usually conflicts with routing that NetworkManager configures for WireGuard interfaces, so usually it should not be set in that case. See \"ip4-auto-default-route\".") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured name servers and search domains are ignored and only name servers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured routes are ignored and only routes specified in the \"routes\" property, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_LINK_LOCAL N_("Enable and disable the IPv4 link-local configuration independently of the ipv4.method configuration. This allows a link-local address (169.254.x.y/16) to be obtained in addition to other addresses, such as those manually configured or obtained from a DHCP server. When set to \"auto\", the value is dependent on \"ipv4.method\". When set to \"default\", it honors the global connection default, before falling back to \"auto\". Note that if \"ipv4.method\" is \"disabled\", then link local addressing is always disabled too. The default is \"default\". Since 1.40") @@ -197,7 +197,7 @@ #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_OPTIONS N_("Array of DNS options as described in man 5 resolv.conf. NULL means that the options are unset and left at the default. In this case NetworkManager will use default options. This is distinct from an empty list of properties. The currently supported options are \"attempts\", \"debug\", \"edns0\", \"inet6\", \"ip6-bytestring\", \"ip6-dotint\", \"ndots\", \"no-check-names\", \"no-ip6-dotint\", \"no-reload\", \"no-tld-query\", \"rotate\", \"single-request\", \"single-request-reopen\", \"timeout\", \"trust-ad\", \"use-vc\". The \"trust-ad\" setting is only honored if the profile contributes name servers to resolv.conf, and if all contributing profiles have \"trust-ad\" enabled. When using a caching DNS plugin (dnsmasq or systemd-resolved in NetworkManager.conf) then \"edns0\" and \"trust-ad\" are automatically added.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower numerical value is better (higher priority). Negative values have the special effect of excluding other configurations with a greater numerical priority value; so in presence of at least one negative priority, only DNS servers from connections with the lowest priority value will be used. To avoid all DNS leaks, set the priority of the profile that should be used to the most negative value of all active connections profiles. Zero selects a globally configured default value. If the latter is missing or zero too, it defaults to 50 for VPNs (including WireGuard) and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When multiple devices have configurations with the same priority, VPNs will be considered first, then devices with the best (lowest metric) default route and then all other devices. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. Note that commonly the resolver tries name servers in /etc/resolv.conf in the order listed, proceeding with the next server in the list on failure. See for example the \"rotate\" option of the dns-options setting. If there are any negative DNS priorities, then only name servers from the devices with that lowest priority will be considered. When using a DNS resolver that supports Conditional Forwarding or Split DNS (with dns=dnsmasq or dns=systemd-resolved settings), each connection is used to query domains in its search list. The search domains determine which name servers to ask, and the DNS priority is used to prioritize name servers based on the domain. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the best priority (lowest numerical value) wins. If a sub domain is configured on another interface it will be accepted regardless the priority, unless parent domain on the other interface has a negative priority, which causes the sub domain to be shadowed. With Split DNS one can avoid undesired DNS leaks by properly configuring DNS priorities and the search domains, so that only name servers of the desired interface are configured.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_SEARCH N_("List of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names. When using a DNS plugin that supports Conditional Forwarding or Split DNS, then the search domains specify which name servers to query. This makes the behavior different from running with plain /etc/resolv.conf. For more information see also the dns-priority setting. When set on a profile that also enabled DHCP, the DNS search list received automatically (option 119 for DHCPv4 and option 24 for DHCPv6) gets merged with the manual list. This can be prevented by setting \"ignore-auto-dns\". Note that if no DNS searches are configured, the fallback will be derived from the domain from DHCP (option 15).") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_GATEWAY N_("The gateway associated with this configuration. This is only meaningful if \"addresses\" is also set. The gateway's main purpose is to control the next hop of the standard default route on the device. Hence, the gateway property conflicts with \"never-default\" and will be automatically dropped if the IP configuration is set to never-default. As an alternative to set the gateway, configure a static default route with /0 as prefix length.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_GATEWAY N_("The gateway associated with this configuration. This is only meaningful if \"addresses\" is also set. Setting the gateway causes NetworkManager to configure a standard default route with the gateway as next hop. This is ignored if \"never-default\" is set. An alternative is to configure the default route explicitly with a manual route and /0 as prefix length. Note that the gateway usually conflicts with routing that NetworkManager configures for WireGuard interfaces, so usually it should not be set in that case. See \"ip4-auto-default-route\".") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured name servers and search domains are ignored and only name servers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured routes are ignored and only routes specified in the \"routes\" property, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IP6_PRIVACY N_("Configure IPv6 Privacy Extensions for SLAAC, described in RFC4941. If enabled, it makes the kernel generate a temporary IPv6 address in addition to the public one generated from MAC address via modified EUI-64. This enhances privacy, but could cause problems in some applications, on the other hand. The permitted values are: -1: unknown, 0: disabled, 1: enabled (prefer public address), 2: enabled (prefer temporary addresses). Having a per-connection setting set to \"-1\" (unknown) means fallback to global configuration \"ipv6.ip6-privacy\". If also global configuration is unspecified or set to \"-1\", fallback to read \"/proc/sys/net/ipv6/conf/default/use_tempaddr\". Note that this setting is distinct from the Stable Privacy addresses that can be enabled with the \"addr-gen-mode\" property's \"stable-privacy\" setting as another way of avoiding host tracking with IPv6 addresses.") diff --git a/src/nmcli/generate-docs-nm-settings-nmcli.xml.in b/src/nmcli/generate-docs-nm-settings-nmcli.xml.in index 85df9ce54b..e203316ebf 100644 --- a/src/nmcli/generate-docs-nm-settings-nmcli.xml.in +++ b/src/nmcli/generate-docs-nm-settings-nmcli.xml.in @@ -664,7 +664,7 @@ description="A list of IPv4 addresses and their prefix length. Multiple addresses can be separated by comma. For example "192.168.1.5/24, 10.1.0.5/24". The addresses are listed in decreasing priority, meaning the first address will be the primary address." /> + description="The gateway associated with this configuration. This is only meaningful if "addresses" is also set. Setting the gateway causes NetworkManager to configure a standard default route with the gateway as next hop. This is ignored if "never-default" is set. An alternative is to configure the default route explicitly with a manual route and /0 as prefix length. Note that the gateway usually conflicts with routing that NetworkManager configures for WireGuard interfaces, so usually it should not be set in that case. See "ip4-auto-default-route"." /> + description="The gateway associated with this configuration. This is only meaningful if "addresses" is also set. Setting the gateway causes NetworkManager to configure a standard default route with the gateway as next hop. This is ignored if "never-default" is set. An alternative is to configure the default route explicitly with a manual route and /0 as prefix length. Note that the gateway usually conflicts with routing that NetworkManager configures for WireGuard interfaces, so usually it should not be set in that case. See "ip4-auto-default-route"." /> Date: Tue, 23 Aug 2022 15:37:01 +0200 Subject: contrib: install Polish translation in "nm-in-container.sh" It's needed for the unit tests to test translations too. --- contrib/scripts/nm-in-container.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contrib/scripts/nm-in-container.sh b/contrib/scripts/nm-in-container.sh index 21ad8430dd..28fa58b425 100755 --- a/contrib/scripts/nm-in-container.sh +++ b/contrib/scripts/nm-in-container.sh @@ -289,6 +289,8 @@ FROM $BASE_IMAGE ENTRYPOINT ["/sbin/init"] +RUN sed -i 's/^tsflags=.*/tsflags=/' /etc/dnf/dnf.conf + RUN dnf install -y \\ /usr/bin/python \\ ModemManager-devel \\ @@ -310,6 +312,7 @@ RUN dnf install -y \\ gettext-devel \\ git \\ glib2-doc \\ + glibc-langpack-pl \\ gnutls-devel \\ gobject-introspection-devel \\ gtk-doc \\ -- cgit v1.2.1 From 8959083784350d6594ab600e8b36345d622e9636 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 23 Aug 2022 15:17:32 +0200 Subject: tests: skip test in "test-client.py" if the pexepect dependency is not available --- src/tests/client/test-client.py | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/tests/client/test-client.py b/src/tests/client/test-client.py index 6b2c51f526..7204987e31 100755 --- a/src/tests/client/test-client.py +++ b/src/tests/client/test-client.py @@ -95,16 +95,6 @@ ENV_NM_TEST_UBSAN_OPTIONS = "NM_TEST_UBSAN_OPTIONS" import sys -try: - import gi - from gi.repository import GLib - - gi.require_version("NM", "1.0") - from gi.repository import NM -except Exception as e: - GLib = None - NM = None - import os import errno import unittest @@ -120,7 +110,27 @@ import random import dbus.service import dbus.mainloop.glib import io -import pexpect + +moduleNotFoundError = ModuleNotFoundError if sys.version_info[0] >= 3 else ImportError + +import gi + +try: + from gi.repository import GLib +except ImportError as e: + GLib = None + +try: + gi.require_version("NM", "1.0") + from gi.repository import NM +except ImportError as e: + NM = None + +try: + import pexpect +except moduleNotFoundError: + pexpect = None + ############################################################################### @@ -1206,6 +1216,14 @@ class TestNmcli(NmTestBase): % (",".join(skip_test_for_l10n_diff)) ) + def skip_without_pexpect(func): + def f(self): + if pexpect is None: + raise unittest.SkipTest("pexpect not available") + func(self) + + return f + def nm_test(func): def f(self): self.srv = NMStubServer(self._testMethodName) @@ -1842,6 +1860,7 @@ class TestNmcli(NmTestBase): extra_env=no_dbus_env, ) + @skip_without_pexpect @nm_test def test_ask_mode(self): nmc = self.call_nmcli_pexpect(["--ask", "c", "add"]) -- cgit v1.2.1 From dc01d353aa3f2d40852d875e0697f32895c0e4c8 Mon Sep 17 00:00:00 2001 From: Ana Cabral Date: Wed, 24 Aug 2022 10:38:21 +0200 Subject: NEWS: update --- NEWS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 70feb554d9..fb248aecb5 100644 --- a/NEWS +++ b/NEWS @@ -51,8 +51,9 @@ and 1.38.4 are also present in NetworkManager-1.40: - 1.38.4 +* Fix DAD for DHCPv6 addresses. * Wi-Fi: improvements for OWE networks. -* Support EC private keys +* Support EC private keys. * Fix nmcli tab completion support for embedded quote characters. * Fix reapply for lldp/mdns/llmnr/dns-over-tls settings. * Various bugfixes. -- cgit v1.2.1 From 90b267afa71dbeede500fead20bc5ce2ade3218f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 19 Aug 2022 13:45:47 +0200 Subject: contrib: add "--fast" flag to nm-core-format.sh to only check changed files It's not the default, because a caller might not be aware that this flag exists, and when calling the script without arguments, it should do correct (albeit slow) thing. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1341 --- contrib/scripts/nm-code-format.sh | 50 ++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/contrib/scripts/nm-code-format.sh b/contrib/scripts/nm-code-format.sh index 0aaa14752c..cd45874f16 100755 --- a/contrib/scripts/nm-code-format.sh +++ b/contrib/scripts/nm-code-format.sh @@ -47,26 +47,28 @@ FILES=() HAS_EXPLICIT_FILES=0 SHOW_FILENAMES=0 TEST_ONLY=0 +CHECK_ALL=1 usage() { printf "Usage: %s [OPTION]... [FILE]...\n" "$(basename "$0")" printf "Reformat source files using NetworkManager's code-style.\n\n" printf "If no file is given the script runs on the whole codebase.\n" printf "OPTIONS:\n" - printf " -i Reformat files (this is the default)\n" - printf " -n|--dry-run Only check the files (contrary to \"-i\")\n" - printf " -h Print this help message\n" + printf " -h Print this help message.\n" + printf " -i Reformat files (the default).\n" + printf " -n|--dry-run Only check the files (contrary to \"-i\").\n" + printf " -a|--all Check all files (the default).\n" + printf " -F|--fast Check only files from \`git diff --name-only HEAD^\` (contrary to \"-a\").\n" + printf " This also affects directories given in the [FILE] list, but not files.\n" printf " --show-filenames Only print the filenames that would be checked/formatted\n" printf " -- Separate options from filenames/directories\n" } -g_ls_files() { +ls_files_filter() { local OLD_IFS="$IFS" - local pattern="$1" - shift IFS=$'\n' - for f in $(git ls-files -- "$pattern") ; do + for f in $(cat) ; do local found=1 local p for p; do @@ -78,6 +80,17 @@ g_ls_files() { IFS="$OLD_IFS" } +g_ls_files() { + local pattern="$1" + shift + + if [ $CHECK_ALL = 1 ]; then + git ls-files -- "$pattern" + else + git diff --name-only HEAD^ -- "$pattern" + fi | ls_files_filter "$@" +} + HAD_DASHDASH=0 while (( $# )); do if [ "$HAD_DASHDASH" = 0 ]; then @@ -91,6 +104,16 @@ while (( $# )); do shift continue ;; + -a|--all) + CHECK_ALL=1 + shift + continue + ;; + -F|--fast) + CHECK_ALL=0 + shift + continue + ;; -n|--dry-run) TEST_ONLY=1 shift @@ -111,7 +134,7 @@ while (( $# )); do if [ -d "$1" ]; then while IFS='' read -r line; do FILES+=("$line") - done < <(g_ls_files "${1}/*.[hc]" "${EXCLUDE_PATHS[@]}") + done < <(CHECK_ALL=$CHECK_ALL g_ls_files "${1}/*.[hc]" "${EXCLUDE_PATHS[@]}") elif [ -f "$1" ]; then FILES+=("$1") else @@ -126,16 +149,21 @@ done if [ $HAS_EXPLICIT_FILES = 0 ]; then while IFS='' read -r line; do FILES+=("$line") - done < <(g_ls_files '*.[ch]' "${EXCLUDE_PATHS[@]}") + done < <(CHECK_ALL=$CHECK_ALL g_ls_files '*.[ch]' "${EXCLUDE_PATHS[@]}") fi if [ $SHOW_FILENAMES = 1 ]; then - printf '%s\n' "${FILES[@]}" + for f in "${FILES[@]}" ; do + printf '%s\n' "$f" + done exit 0 fi if [ "${#FILES[@]}" = 0 ]; then - die "Error: no files to check" + if [ $CHECK_ALL = 1 ]; then + die "Error: no files to check" + fi + exit 0 fi FLAGS_TEST=( --Werror -n --ferror-limit=1 ) -- cgit v1.2.1 From f7e484c8eda484bed8ce98546fc1da6a86d91a26 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 24 Aug 2022 14:00:57 +0200 Subject: tests: fix "test-client.py" ignoring missing "NM" module Fixes: 895908378435 ('tests: skip test in "test-client.py" if the pexepect dependency is not available') --- src/tests/client/test-client.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/tests/client/test-client.py b/src/tests/client/test-client.py index 7204987e31..68cc08e86d 100755 --- a/src/tests/client/test-client.py +++ b/src/tests/client/test-client.py @@ -117,14 +117,18 @@ import gi try: from gi.repository import GLib -except ImportError as e: +except ImportError: GLib = None try: gi.require_version("NM", "1.0") - from gi.repository import NM -except ImportError as e: +except ValueError: NM = None +else: + try: + from gi.repository import NM + except ImportError: + NM = None try: import pexpect -- cgit v1.2.1 From cfe44c8832d60215a7196d39455e1dd66eaef267 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 24 Aug 2022 15:46:13 +0200 Subject: gitlab-ci: fix preserving build artifacts and documentation pages Without it, the build artifacts were deleted before getting archived. It means, the tarball and the docs were no longer archived and no pages on gitlab no longer updated. Fixes: e1182762965d ('gitlab-ci: run unit tests for git subtree subprojects') --- .gitlab-ci/run-test.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci/run-test.sh b/.gitlab-ci/run-test.sh index dfaee99ba8..a91b8b7360 100755 --- a/.gitlab-ci/run-test.sh +++ b/.gitlab-ci/run-test.sh @@ -28,6 +28,10 @@ do_clean() { git diff } +ARTIFACT_DIR=/tmp/nm-artifact +rm -rf "$ARTIFACT_DIR" +mkdir -p "$ARTIFACT_DIR" + uname -a ! command -v locale &>/dev/null || locale -a meson --version @@ -43,8 +47,7 @@ meson --version export NMTST_SKIP_CHECK_GITLAB_CI=1 do_clean; BUILD_TYPE=autotools CC=gcc WITH_DOCS=1 WITH_VALGRIND=1 contrib/scripts/nm-ci-run.sh -rm -rf /tmp/nm-docs-html; -mv build/INST/share/gtk-doc/html /tmp/nm-docs-html +mv build/INST/share/gtk-doc/html "$ARTIFACT_DIR/docs-html" do_clean; BUILD_TYPE=meson CC=gcc WITH_DOCS=1 WITH_VALGRIND=1 contrib/scripts/nm-ci-run.sh do_clean; BUILD_TYPE=autotools CC=clang WITH_DOCS=0 contrib/scripts/nm-ci-run.sh do_clean; BUILD_TYPE=meson CC=clang WITH_DOCS=0 contrib/scripts/nm-ci-run.sh @@ -57,11 +60,9 @@ do_clean; test $IS_FEDORA = 1 && ./contrib/fedora/rpm/build_cl do_clean if [ "$NM_BUILD_TARBALL" = 1 ]; then SIGN_SOURCE=0 ./contrib/fedora/rpm/build_clean.sh -r - mv ./NetworkManager-1*.tar.xz /tmp/ - mv ./contrib/fedora/rpm/latest/SRPMS/NetworkManager-1*.src.rpm /tmp/ + mv ./NetworkManager-1*.tar.xz "$ARTIFACT_DIR/" + mv ./contrib/fedora/rpm/latest/SRPMS/NetworkManager-1*.src.rpm "$ARTIFACT_DIR/" do_clean - mv /tmp/nm-docs-html ./docs-html - mv /tmp/NetworkManager-1*.tar.xz /tmp/NetworkManager-1*.src.rpm ./ fi ############################################################################### @@ -97,4 +98,13 @@ done ############################################################################### +do_clean + +if [ "$NM_BUILD_TARBALL" = 1 ]; then + mv "$ARTIFACT_DIR/docs-html/" \ + "$ARTIFACT_DIR"/NetworkManager-1*.tar.xz \ + "$ARTIFACT_DIR"/NetworkManager-1*.src.rpm \ + ./ +fi + echo "BUILD SUCCESSFUL!!" -- cgit v1.2.1 From cbc235485463e8f33409db73dfbb55f67b84de3b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 24 Aug 2022 20:37:27 +0200 Subject: wifi: drop duplicate include in "nm-device-wifi-p2p.c" Base-on-patch-by: Andrew Zaborowski --- src/core/devices/wifi/nm-device-wifi-p2p.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/devices/wifi/nm-device-wifi-p2p.c b/src/core/devices/wifi/nm-device-wifi-p2p.c index 4576af95cb..6c0a4d5e8d 100644 --- a/src/core/devices/wifi/nm-device-wifi-p2p.c +++ b/src/core/devices/wifi/nm-device-wifi-p2p.c @@ -22,7 +22,6 @@ #include "nm-act-request.h" #include "nm-l3-config-data.h" #include "nm-manager.h" -#include "nm-manager.h" #include "nm-setting-wifi-p2p.h" #include "nm-utils.h" #include "nm-wifi-p2p-peer.h" -- cgit v1.2.1 From e384ab74c24ba329db083ed22bbf91578049896b Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Fri, 12 Aug 2022 12:32:16 +0200 Subject: iwd: Be extra careful not to interrupt assumed activation The IWD backend would originally use .Disconnect() on IWD dbus "Station" objects to make sure IWD is out of autoconnect or that it isn't connecting to a network that NM didn't command. Later the default became to let IWD run autoconnect so now most of the time the backend just mirrors IWD's state to NMDevice's state. Now sometimes when NMDevice still seems to have an active connection but IWD has gone through one or more state changes (which we may see after a delay due to D-Bus) and is now connected to or connecting to a different network, NMDevice would first have to go through .deactivate to mirror the fact the original connection is no longer active, and it'd use .Disconnect() which could break the new connection, so check for this situation. --- src/core/devices/wifi/nm-device-iwd.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/core/devices/wifi/nm-device-iwd.c b/src/core/devices/wifi/nm-device-iwd.c index ab37cbec91..aadfc115ea 100644 --- a/src/core/devices/wifi/nm-device-iwd.c +++ b/src/core/devices/wifi/nm-device-iwd.c @@ -70,6 +70,7 @@ typedef struct { bool secrets_failed : 1; bool networks_requested : 1; bool networks_changed : 1; + bool assuming : 1; gint64 last_scan; uint32_t ap_id; guint32 rate; @@ -581,6 +582,10 @@ deactivate(NMDevice *device) if (!priv->dbus_obj) return; + /* Don't cause IWD to break the connection being assumed */ + if (priv->assuming) + return; + if (priv->dbus_station_proxy) { gs_unref_variant GVariant *value = g_dbus_proxy_get_cached_property(priv->dbus_station_proxy, "State"); @@ -2719,12 +2724,20 @@ state_changed(NMDeviceIwd *self, const char *new_state) "IWD is connecting to the wrong AP, %s activation", switch_ap ? "replacing" : "aborting"); cleanup_association_attempt(self, !switch_ap); + + if (!switch_ap) { + nm_device_state_changed(device, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT); + return; + } + + priv->assuming = TRUE; /* Don't send Station.Disconnect() */ nm_device_state_changed(device, - NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT); - - if (switch_ap) - assume_connection(self, ap); + priv->assuming = FALSE; + assume_connection(self, ap); return; } -- cgit v1.2.1 From f6cec3b584ed263986ca9ececf345d3a52a8c8f9 Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Fri, 12 Aug 2022 12:43:31 +0200 Subject: iwd: Let IWD handle retries When we're set to let IWD control autoconnect, don't retry connections on NM side, set retry count to 0. --- src/core/devices/wifi/nm-device-iwd.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/core/devices/wifi/nm-device-iwd.c b/src/core/devices/wifi/nm-device-iwd.c index aadfc115ea..73232e3414 100644 --- a/src/core/devices/wifi/nm-device-iwd.c +++ b/src/core/devices/wifi/nm-device-iwd.c @@ -2275,6 +2275,18 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) goto out_fail; } + /* With priv->iwd_autoconnect we have to let IWD handle retries for + * infrastructure networks. IWD will not necessarily retry the same + * network after a failure but it will likely go into an autoconnect + * mode and we don't want to try to override the logic. We don't need + * to reset the retry count so we set no timeout. + */ + if (priv->iwd_autoconnect) { + NMSettingsConnection *sett_conn = nm_act_request_get_settings_connection(req); + + nm_settings_connection_autoconnect_retries_set(sett_conn, 0); + } + /* With priv->iwd_autoconnect, if we're assuming a connection because * of a state change to "connecting", signal stage 2 is still running. * If "connected" or "roaming", we can go right to the IP_CONFIG state -- cgit v1.2.1 From 824f2f26db465c67339260e10a728ef6f25a4c7f Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Sat, 13 Aug 2022 02:37:18 +0200 Subject: iwd: Work around timing when new 802.1x connection activated Try work around the issue documented by Emil Velikov in https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1264 When we mirror an 802.1x connection to an IWD config file and there's an AP in range with matching SSID, that connection should become available for activation. In IWD terms when an 802.1x network becomes a Known Network, it can be connected to using the .Connect D-Bus method. However there's a delay between writing the IWD config file and receiving the InterfaceAdded event for the Known Network so we don't immediately find out that the network can now be used. If an NM client creates a new connection for an 802.1x AP and tries to activate it quickly enough, NMDeviceIWD will not allow it to because it won't know the network is known yet. To work around this, we save the SSIDs of 802.1x connections we recently mirrored to IWD config files, for an arbitrary 2 seconds period, and we treat them as Known Networks in that period since in theory activations should succeed. The alternative proposed in the !1264 is to drop NMDeviceIWD checks that there's a Known Network for the 802.1x connection being activated since IWD will eventually perform the same checks and IWD is the ultimate authority on whether the profile is IWD-connectable. --- src/core/devices/wifi/nm-device-iwd.c | 11 +++-- src/core/devices/wifi/nm-iwd-manager.c | 82 ++++++++++++++++++++++++++++++++++ src/core/devices/wifi/nm-iwd-manager.h | 2 + 3 files changed, 92 insertions(+), 3 deletions(-) diff --git a/src/core/devices/wifi/nm-device-iwd.c b/src/core/devices/wifi/nm-device-iwd.c index 73232e3414..300ec7c94c 100644 --- a/src/core/devices/wifi/nm-device-iwd.c +++ b/src/core/devices/wifi/nm-device-iwd.c @@ -799,7 +799,8 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * * thus are Known Networks. */ if (security == NM_IWD_NETWORK_SECURITY_8021X) { - if (!is_connection_known_network(connection)) { + if (!is_connection_known_network(connection) + && !nm_iwd_manager_is_recently_mirrored(nm_iwd_manager_get(), ssid)) { nm_utils_error_set_literal(error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_INCOMPATIBLE, "802.1x connections must have IWD provisioning files"); @@ -932,7 +933,9 @@ check_connection_available(NMDevice *device, */ if (nm_wifi_connection_get_iwd_ssid_and_security(connection, NULL, &security) && security == NM_IWD_NETWORK_SECURITY_8021X) { - if (!is_ap_known_network(ap)) { + if (!is_ap_known_network(ap) + && !nm_iwd_manager_is_recently_mirrored(nm_iwd_manager_get(), + nm_setting_wireless_get_ssid(s_wifi))) { nm_utils_error_set_literal( error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, @@ -2327,7 +2330,9 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) * fail, for other combinations we will let the Connect call fail * or ask us for any missing secrets through the Agent. */ - if (nm_connection_get_setting_802_1x(connection) && !is_ap_known_network(ap)) { + if (nm_connection_get_setting_802_1x(connection) && !is_ap_known_network(ap) + && !nm_iwd_manager_is_recently_mirrored(nm_iwd_manager_get(), + nm_setting_wireless_get_ssid(s_wireless))) { _LOGI(LOGD_DEVICE | LOGD_WIFI, "Activation: (wifi) access point '%s' has 802.1x security but is not configured " "in IWD.", diff --git a/src/core/devices/wifi/nm-iwd-manager.c b/src/core/devices/wifi/nm-iwd-manager.c index 2e0d51e5d8..ec111329a2 100644 --- a/src/core/devices/wifi/nm-iwd-manager.c +++ b/src/core/devices/wifi/nm-iwd-manager.c @@ -46,6 +46,11 @@ typedef struct { const KnownNetworkId *id; } KnownNetworkData; +typedef struct { + GBytes *ssid; + gint64 timestamp; +} RecentlyMirroredData; + typedef struct { NMManager *manager; NMSettings *settings; @@ -62,6 +67,7 @@ typedef struct { GHashTable *p2p_devices; NMIwdWfdInfo wfd_info; guint wfd_use_count; + GSList *recently_mirrored; } NMIwdManagerPrivate; struct _NMIwdManager { @@ -353,6 +359,70 @@ register_agent(NMIwdManager *self) /*****************************************************************************/ +static void +recently_mirrored_data_free(void *data) +{ + RecentlyMirroredData *rmd = data; + + g_bytes_unref(rmd->ssid); + g_free(rmd); +} + +/* When we mirror an 802.1x connection to an IWD config file, and there's an + * AP in range with matching SSID, that connection should become available + * for activation. In IWD terms when an 802.1x network becomes a Known + * Network, it can be connected to using the .Connect D-Bus method. + * + * However there's a delay between writing the IWD config file and receiving + * the InterfaceAdded event for the Known Network so we don't immediately + * find out that the network can now be used. If an NM client creates a + * new connection for an 802.1x AP and tries to activate it immediately, + * NMDeviceIWD will not allow it to because it doesn't know the network is + * known yet. To work around this, we save the SSIDs of 802.1x connections + * we recently mirrored to IWD config files, for 2 seconds, and we treat + * them as Known Networks in that period since in theory activations should + * succeed. + */ +bool +nm_iwd_manager_is_recently_mirrored(NMIwdManager *self, const GBytes *ssid) +{ + NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); + gint64 now = nm_utils_get_monotonic_timestamp_nsec(); + GSList *iter; + RecentlyMirroredData *rmd; + + /* Drop entries older than 2 seconds */ + while (priv->recently_mirrored) { + rmd = priv->recently_mirrored->data; + if (now < rmd->timestamp + 2000000000) + break; + + priv->recently_mirrored = g_slist_remove(priv->recently_mirrored, rmd); + recently_mirrored_data_free(rmd); + } + + for (iter = priv->recently_mirrored; iter; iter = iter->next) { + rmd = iter->data; + if (g_bytes_equal(ssid, rmd->ssid)) + return TRUE; + } + + return FALSE; +} + +static void +save_mirrored(NMIwdManager *self, GBytes *ssid) +{ + NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); + RecentlyMirroredData *rmd = g_malloc(sizeof(RecentlyMirroredData)); + + rmd->ssid = g_bytes_ref(ssid); + rmd->timestamp = nm_utils_get_monotonic_timestamp_nsec(); + priv->recently_mirrored = g_slist_append(priv->recently_mirrored, rmd); +} + +/*****************************************************************************/ + static KnownNetworkId * known_network_id_new(const char *name, NMIwdNetworkSecurity security) { @@ -721,6 +791,9 @@ sett_conn_changed(NMSettingsConnection *sett_conn, "iwd: changed Wi-Fi connection %s mirrored as IWD profile %s", nm_settings_connection_get_id(sett_conn), full_path); + + if (security == NM_IWD_NETWORK_SECURITY_8021X) + save_mirrored(nm_iwd_manager_get(), ssid); } /* Look up an existing NMSettingsConnection for a network that has been @@ -1283,6 +1356,7 @@ connection_added(NMSettings *settings, NMSettingsConnection *sett_conn, gpointer gs_free_error GError *error = NULL; nm_auto_unref_keyfile GKeyFile *iwd_config = NULL; NMSettingsConnectionIntFlags flags; + NMIwdNetworkSecurity security; if (!nm_streq(nm_settings_connection_get_connection_type(sett_conn), "802-11-wireless")) return; @@ -1338,6 +1412,12 @@ connection_added(NMSettings *settings, NMSettingsConnection *sett_conn, gpointer _LOGD("New Wi-Fi connection %s mirrored as IWD profile %s", nm_settings_connection_get_id(sett_conn), full_path); + + if (nm_wifi_connection_get_iwd_ssid_and_security(conn, NULL, &security) + && security == NM_IWD_NETWORK_SECURITY_8021X) { + NMSettingWireless *s_wifi = nm_connection_get_setting_wireless(conn); + save_mirrored(nm_iwd_manager_get(), nm_setting_wireless_get_ssid(s_wifi)); + } } static gboolean @@ -1952,6 +2032,8 @@ dispose(GObject *object) g_hash_table_unref(nm_steal_pointer(&priv->p2p_devices)); + g_slist_free_full(nm_steal_pointer(&priv->recently_mirrored), recently_mirrored_data_free); + G_OBJECT_CLASS(nm_iwd_manager_parent_class)->dispose(object); } diff --git a/src/core/devices/wifi/nm-iwd-manager.h b/src/core/devices/wifi/nm-iwd-manager.h index 02cd6bba50..80a2753462 100644 --- a/src/core/devices/wifi/nm-iwd-manager.h +++ b/src/core/devices/wifi/nm-iwd-manager.h @@ -63,4 +63,6 @@ gboolean nm_iwd_manager_check_wfd_info_compatible(NMIwdManager *self, const NMIw gboolean nm_iwd_manager_register_wfd(NMIwdManager *self, const NMIwdWfdInfo *wfd_info); void nm_iwd_manager_unregister_wfd(NMIwdManager *self); +bool nm_iwd_manager_is_recently_mirrored(NMIwdManager *self, const GBytes *ssid); + #endif /* __NETWORKMANAGER_IWD_MANAGER_H__ */ -- cgit v1.2.1 From e3eac0908235e20b3e96f45566cf953272c027a8 Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Wed, 24 Aug 2022 20:16:56 +0200 Subject: iwd: nm_iwd_manager_get() once and save value Call nm_iwd_manager_get once on NMDeviceIwd creation and save in priv->manager to avoid using t very often now that we have 5 new call sites. The reasoning is explained in https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1338#note_1519684 --- src/core/devices/wifi/nm-device-iwd.c | 37 ++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/core/devices/wifi/nm-device-iwd.c b/src/core/devices/wifi/nm-device-iwd.c index 300ec7c94c..c10afdecdf 100644 --- a/src/core/devices/wifi/nm-device-iwd.c +++ b/src/core/devices/wifi/nm-device-iwd.c @@ -78,6 +78,7 @@ typedef struct { GDBusMethodInvocation *pending_agent_request; NMActiveConnection *assumed_ac; guint assumed_ac_timeout; + NMIwdManager *manager; } NMDeviceIwdPrivate; struct _NMDeviceIwd { @@ -290,6 +291,7 @@ insert_ap_from_network(NMDeviceIwd *self, gint64 last_seen_msec, int16_t signal) { + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); gs_unref_object GDBusProxy *network_proxy = NULL; nm_auto_ref_string NMRefString *bss_path = nm_ref_string_new(path); NMWifiAP *ap; @@ -300,7 +302,7 @@ insert_ap_from_network(NMDeviceIwd *self, } network_proxy = - nm_iwd_manager_get_dbus_interface(nm_iwd_manager_get(), path, NM_IWD_NETWORK_INTERFACE); + nm_iwd_manager_get_dbus_interface(priv->manager, path, NM_IWD_NETWORK_INTERFACE); ap = ap_from_network(self, network_proxy, bss_path, last_seen_msec, signal); if (!ap) @@ -678,7 +680,7 @@ deactivate_async(NMDevice *device, } static gboolean -is_connection_known_network(NMConnection *connection) +is_connection_known_network(NMIwdManager *manager, NMConnection *connection) { NMIwdNetworkSecurity security; gs_free char *ssid = NULL; @@ -686,17 +688,17 @@ is_connection_known_network(NMConnection *connection) if (!nm_wifi_connection_get_iwd_ssid_and_security(connection, &ssid, &security)) return FALSE; - return nm_iwd_manager_is_known_network(nm_iwd_manager_get(), ssid, security); + return nm_iwd_manager_is_known_network(manager, ssid, security); } static gboolean -is_ap_known_network(NMWifiAP *ap) +is_ap_known_network(NMIwdManager *manager, NMWifiAP *ap) { gs_unref_object GDBusProxy *network_proxy = NULL; gs_unref_variant GVariant *known_network = NULL; network_proxy = - nm_iwd_manager_get_dbus_interface(nm_iwd_manager_get(), + nm_iwd_manager_get_dbus_interface(manager, nm_ref_string_get_str(nm_wifi_ap_get_supplicant_path(ap)), NM_IWD_NETWORK_INTERFACE); if (!network_proxy) @@ -799,8 +801,8 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * * thus are Known Networks. */ if (security == NM_IWD_NETWORK_SECURITY_8021X) { - if (!is_connection_known_network(connection) - && !nm_iwd_manager_is_recently_mirrored(nm_iwd_manager_get(), ssid)) { + if (!is_connection_known_network(priv->manager, connection) + && !nm_iwd_manager_is_recently_mirrored(priv->manager, ssid)) { nm_utils_error_set_literal(error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_INCOMPATIBLE, "802.1x connections must have IWD provisioning files"); @@ -933,8 +935,8 @@ check_connection_available(NMDevice *device, */ if (nm_wifi_connection_get_iwd_ssid_and_security(connection, NULL, &security) && security == NM_IWD_NETWORK_SECURITY_8021X) { - if (!is_ap_known_network(ap) - && !nm_iwd_manager_is_recently_mirrored(nm_iwd_manager_get(), + if (!is_ap_known_network(priv->manager, ap) + && !nm_iwd_manager_is_recently_mirrored(priv->manager, nm_setting_wireless_get_ssid(s_wifi))) { nm_utils_error_set_literal( error, @@ -2052,7 +2054,7 @@ assume_connection(NMDeviceIwd *self, NMWifiAP *ap) * becomes "managed" only when ACTIVATED but for IWD it's really * managed when IP_CONFIG starts. */ - sett_conn = nm_iwd_manager_get_ap_mirror_connection(nm_iwd_manager_get(), ap); + sett_conn = nm_iwd_manager_get_ap_mirror_connection(priv->manager, ap); if (!sett_conn) goto error; @@ -2225,7 +2227,8 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) * for a first-time connection to a hidden network. If a hidden network is * a Known Network it should still have been in the AP list. */ - if (!nm_setting_wireless_get_hidden(s_wireless) || is_connection_known_network(connection)) + if (!nm_setting_wireless_get_hidden(s_wireless) + || is_connection_known_network(priv->manager, connection)) return NM_ACT_STAGE_RETURN_FAILURE; add_new: @@ -2330,8 +2333,8 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) * fail, for other combinations we will let the Connect call fail * or ask us for any missing secrets through the Agent. */ - if (nm_connection_get_setting_802_1x(connection) && !is_ap_known_network(ap) - && !nm_iwd_manager_is_recently_mirrored(nm_iwd_manager_get(), + if (nm_connection_get_setting_802_1x(connection) && !is_ap_known_network(priv->manager, ap) + && !nm_iwd_manager_is_recently_mirrored(priv->manager, nm_setting_wireless_get_ssid(s_wireless))) { _LOGI(LOGD_DEVICE | LOGD_WIFI, "Activation: (wifi) access point '%s' has 802.1x security but is not configured " @@ -2373,7 +2376,7 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) } network_proxy = nm_iwd_manager_get_dbus_interface( - nm_iwd_manager_get(), + priv->manager, nm_ref_string_get_str(nm_wifi_ap_get_supplicant_path(ap)), NM_IWD_NETWORK_INTERFACE); if (!network_proxy) { @@ -3131,7 +3134,7 @@ nm_device_iwd_set_dbus_object(NMDeviceIwd *self, GDBusObject *object) goto error; } - adapter_proxy = nm_iwd_manager_get_dbus_interface(nm_iwd_manager_get(), + adapter_proxy = nm_iwd_manager_get_dbus_interface(priv->manager, g_variant_get_string(value, NULL), NM_IWD_WIPHY_INTERFACE); if (!adapter_proxy) { @@ -3441,7 +3444,7 @@ nm_device_iwd_init(NMDeviceIwd *self) g_signal_connect(self, "notify::" NM_DEVICE_AUTOCONNECT, G_CALLBACK(autoconnect_changed), self); /* Make sure the manager is running */ - (void) nm_iwd_manager_get(); + priv->manager = g_object_ref(nm_iwd_manager_get()); } NMDevice * @@ -3473,6 +3476,8 @@ dispose(GObject *object) G_OBJECT_CLASS(nm_device_iwd_parent_class)->dispose(object); nm_assert(c_list_is_empty(&priv->aps_lst_head)); + + g_clear_object(&priv->manager); } static void -- cgit v1.2.1 From 032683a824918f4d32b1bb0a7ff1a751c3cbe6eb Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Mon, 22 Aug 2022 12:01:53 +0200 Subject: tui: allow exiting add/edit connection dialog with ESC key No reason this wouldn't be allowed. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1339 --- src/nmtui/nmt-editor.c | 2 ++ src/nmtui/nmtui-edit.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/nmtui/nmt-editor.c b/src/nmtui/nmt-editor.c index 427ac0178b..0fef4e6c3e 100644 --- a/src/nmtui/nmt-editor.c +++ b/src/nmtui/nmt-editor.c @@ -107,6 +107,8 @@ nmt_editor_new(NMConnection *connection) _("Edit Connection"), "fullscreen-vertical", TRUE, + "escape-exits", + TRUE, NULL); } diff --git a/src/nmtui/nmtui-edit.c b/src/nmtui/nmtui-edit.c index ec80a20359..954b0cc26d 100644 --- a/src/nmtui/nmtui-edit.c +++ b/src/nmtui/nmtui-edit.c @@ -398,7 +398,12 @@ nmt_add_connection(void) { NmtNewtForm *form; - form = g_object_new(NMT_TYPE_ADD_CONNECTION, "title", _("New Connection"), NULL); + form = g_object_new(NMT_TYPE_ADD_CONNECTION, + "title", + _("New Connection"), + "escape-exits", + TRUE, + NULL); nmt_newt_form_show(form); g_object_unref(form); } -- cgit v1.2.1 From 350dc1a61bbc670c57241855cc121d179867bf49 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Mon, 22 Aug 2022 12:11:25 +0200 Subject: newt-form: remove escape-exits property As far as I can tell, all forms we have should be dismissable with the Escape key. We omitted settings "escape-exits" property by accident before. Let's just remove it. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1339 --- src/libnmt-newt/nmt-newt-form.c | 26 ++------------------------ src/libnmt-newt/nmt-newt-popup.c | 2 -- src/nmtui/nmt-editor.c | 2 -- src/nmtui/nmt-password-dialog.c | 2 -- src/nmtui/nmtui-connect.c | 11 ++--------- src/nmtui/nmtui-edit.c | 16 ++-------------- src/nmtui/nmtui-hostname.c | 2 +- src/nmtui/nmtui.c | 7 +------ 8 files changed, 8 insertions(+), 60 deletions(-) diff --git a/src/libnmt-newt/nmt-newt-form.c b/src/libnmt-newt/nmt-newt-form.c index 7d28c80e14..de80b42a6c 100644 --- a/src/libnmt-newt/nmt-newt-form.c +++ b/src/libnmt-newt/nmt-newt-form.c @@ -36,7 +36,7 @@ typedef struct { gboolean fixed_width, fixed_height; char *title_lc; - gboolean dirty, escape_exits; + gboolean dirty; NmtNewtWidget *focus; #ifdef HAVE_NEWTFORMGETSCROLLPOSITION int scroll_position = 0; @@ -54,7 +54,6 @@ enum { PROP_WIDTH, PROP_HEIGHT, PROP_PADDING, - PROP_ESCAPE_EXITS, LAST_PROP }; @@ -211,8 +210,7 @@ nmt_newt_form_build(NmtNewtForm *form) } else priv->form = newtForm(NULL, NULL, NEWT_FLAG_NOF12); - if (priv->escape_exits) - newtFormAddHotKey(priv->form, NEWT_KEY_ESCAPE); + newtFormAddHotKey(priv->form, NEWT_KEY_ESCAPE); cos = nmt_newt_widget_get_components(priv->content); for (i = 0; cos[i]; i++) @@ -504,9 +502,6 @@ nmt_newt_form_set_property(GObject *object, guint prop_id, const GValue *value, case PROP_PADDING: priv->padding = g_value_get_uint(value); break; - case PROP_ESCAPE_EXITS: - priv->escape_exits = g_value_get_boolean(value); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -540,9 +535,6 @@ nmt_newt_form_get_property(GObject *object, guint prop_id, GValue *value, GParam case PROP_PADDING: g_value_set_uint(value, priv->padding); break; - case PROP_ESCAPE_EXITS: - g_value_set_boolean(value, priv->escape_exits); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -722,18 +714,4 @@ nmt_newt_form_class_init(NmtNewtFormClass *form_class) G_MAXUINT, 1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY)); - /** - * NmtNewtForm:escape-exits: - * - * If %TRUE, then hitting the Escape key will cause the form to - * exit. - */ - g_object_class_install_property( - object_class, - PROP_ESCAPE_EXITS, - g_param_spec_boolean("escape-exits", - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY)); } diff --git a/src/libnmt-newt/nmt-newt-popup.c b/src/libnmt-newt/nmt-newt-popup.c index c62951ca5d..8e99ac6580 100644 --- a/src/libnmt-newt/nmt-newt-popup.c +++ b/src/libnmt-newt/nmt-newt-popup.c @@ -162,8 +162,6 @@ nmt_newt_popup_activated(NmtNewtWidget *widget) list_h, "padding", 0, - "escape-exits", - TRUE, NULL); nmt_newt_form_set_content(form, listbox); diff --git a/src/nmtui/nmt-editor.c b/src/nmtui/nmt-editor.c index 0fef4e6c3e..427ac0178b 100644 --- a/src/nmtui/nmt-editor.c +++ b/src/nmtui/nmt-editor.c @@ -107,8 +107,6 @@ nmt_editor_new(NMConnection *connection) _("Edit Connection"), "fullscreen-vertical", TRUE, - "escape-exits", - TRUE, NULL); } diff --git a/src/nmtui/nmt-password-dialog.c b/src/nmtui/nmt-password-dialog.c index 6189997f27..75194d7b99 100644 --- a/src/nmtui/nmt-password-dialog.c +++ b/src/nmtui/nmt-password-dialog.c @@ -71,8 +71,6 @@ nmt_password_dialog_new(const char *request_id, prompt, "secrets", secrets, - "escape-exits", - TRUE, NULL); } diff --git a/src/nmtui/nmtui-connect.c b/src/nmtui/nmtui-connect.c index fb456653fd..8c4625ec6a 100644 --- a/src/nmtui/nmtui-connect.c +++ b/src/nmtui/nmtui-connect.c @@ -241,7 +241,7 @@ activate_connection(NMConnection *connection, NMDevice *device, NMObject *specif GError *error = NULL; ActivateConnectionInfo info = {}; - form = g_object_new(NMT_TYPE_NEWT_FORM, "escape-exits", TRUE, NULL); + form = g_object_new(NMT_TYPE_NEWT_FORM, NULL); label = nmt_newt_label_new(_("Connecting...")); nmt_newt_form_set_content(form, label); @@ -417,14 +417,7 @@ nmt_connect_connection_list(gboolean is_top) newtGetScreenSize(&screen_width, &screen_height); - form = g_object_new(NMT_TYPE_NEWT_FORM, - "y", - 2, - "height", - screen_height - 4, - "escape-exits", - TRUE, - NULL); + form = g_object_new(NMT_TYPE_NEWT_FORM, "y", 2, "height", screen_height - 4, NULL); grid = nmt_newt_grid_new(); diff --git a/src/nmtui/nmtui-edit.c b/src/nmtui/nmtui-edit.c index 954b0cc26d..173e086274 100644 --- a/src/nmtui/nmtui-edit.c +++ b/src/nmtui/nmtui-edit.c @@ -91,14 +91,7 @@ nmt_edit_main_connection_list(gboolean is_top) newtGetScreenSize(&screen_width, &screen_height); - form = g_object_new(NMT_TYPE_NEWT_FORM, - "y", - 2, - "height", - screen_height - 4, - "escape-exits", - TRUE, - NULL); + form = g_object_new(NMT_TYPE_NEWT_FORM, "y", 2, "height", screen_height - 4, NULL); quit = nmt_newt_button_new(is_top ? _("Quit") : _("Back")); nmt_newt_widget_set_exit_on_activate(quit, TRUE); @@ -398,12 +391,7 @@ nmt_add_connection(void) { NmtNewtForm *form; - form = g_object_new(NMT_TYPE_ADD_CONNECTION, - "title", - _("New Connection"), - "escape-exits", - TRUE, - NULL); + form = g_object_new(NMT_TYPE_ADD_CONNECTION, "title", _("New Connection"), NULL); nmt_newt_form_show(form); g_object_unref(form); } diff --git a/src/nmtui/nmtui-hostname.c b/src/nmtui/nmtui-hostname.c index 65af73cc6c..bdb9753bc0 100644 --- a/src/nmtui/nmtui-hostname.c +++ b/src/nmtui/nmtui-hostname.c @@ -28,7 +28,7 @@ nmtui_hostname_run_dialog(void) NmtNewtButtonBox *bbox; char *hostname, *ret = NULL; - form = g_object_new(NMT_TYPE_NEWT_FORM, "title", _("Set Hostname"), "escape-exits", TRUE, NULL); + form = g_object_new(NMT_TYPE_NEWT_FORM, "title", _("Set Hostname"), NULL); widget = nmt_newt_grid_new(); nmt_newt_form_set_content(form, widget); diff --git a/src/nmtui/nmtui.c b/src/nmtui/nmtui.c index c99d1641f1..37c26e9d43 100644 --- a/src/nmtui/nmtui.c +++ b/src/nmtui/nmtui.c @@ -80,12 +80,7 @@ nmtui_main(gboolean is_top, int argc, char **argv) NmtNewtButtonBox *bbox; int i; - form = g_object_new(NMT_TYPE_NEWT_FORM, - "title", - _("NetworkManager TUI"), - "escape-exits", - TRUE, - NULL); + form = g_object_new(NMT_TYPE_NEWT_FORM, "title", _("NetworkManager TUI"), NULL); widget = nmt_newt_grid_new(); nmt_newt_form_set_content(form, widget); -- cgit v1.2.1 From b58fc7088b2233caea373f6485a5d85dfad3e16e Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Mon, 22 Aug 2022 13:06:31 +0200 Subject: tui/wifi: remove WEP options WEP has been deprecated and is disabled in some distros (RHEL 9) and wpa_supplicant upstream. Let's remove the option of using it, but also keep a chicken bit in form of an environment variable for now. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1340 --- src/nmtui/nmt-page-wifi.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/nmtui/nmt-page-wifi.c b/src/nmtui/nmt-page-wifi.c index 60960e6409..b76463445a 100644 --- a/src/nmtui/nmt-page-wifi.c +++ b/src/nmtui/nmt-page-wifi.c @@ -58,16 +58,22 @@ static NmtNewtPopupEntry wifi_band[] = {{NC_("Wi-Fi", "Automatic"), NULL}, {N_("B/G (2.4 GHz)"), "bg"}, {NULL, NULL}}; -static NmtNewtPopupEntry wifi_security[] = {{NC_("Wi-Fi security", "None"), "none"}, - {N_("WPA & WPA2 Personal"), "wpa-personal"}, - {N_("WPA3 Personal"), "wpa3-personal"}, - {N_("WPA & WPA2 Enterprise"), "wpa-enterprise"}, - {N_("WEP 40/128-bit Key (Hex or ASCII)"), "wep-key"}, - {N_("WEP 128-bit Passphrase"), "wep-passphrase"}, - {N_("Dynamic WEP (802.1x)"), "dynamic-wep"}, - {N_("LEAP"), "leap"}, - {N_("Enhanced Open (OWE)"), "owe"}, - {NULL, NULL}}; +static struct { + NmtNewtPopupEntry common[6]; + NmtNewtPopupEntry wep[4]; +} wifi_security = { + {{NC_("Wi-Fi security", "None"), "none"}, + {N_("WPA & WPA2 Personal"), "wpa-personal"}, + {N_("WPA3 Personal"), "wpa3-personal"}, + {N_("WPA & WPA2 Enterprise"), "wpa-enterprise"}, + {N_("LEAP"), "leap"}, + {N_("Enhanced Open (OWE)"), "owe"}}, + {{N_("WEP 40/128-bit Key (Hex or ASCII)"), "wep-key"}, + {N_("WEP 128-bit Passphrase"), "wep-passphrase"}, + {N_("Dynamic WEP (802.1x)"), "dynamic-wep"}, + {NULL, NULL}}, + +}; static NmtNewtPopupEntry wep_index[] = {{NC_("WEP key index", "1 (Default)"), "1"}, {NC_("WEP key index", "2"), "2"}, @@ -249,7 +255,7 @@ nmt_page_wifi_constructed(GObject *object) nmt_editor_grid_append(grid, NULL, nmt_newt_separator_new(), NULL); - widget = nmt_newt_popup_new(wifi_security); + widget = nmt_newt_popup_new((NmtNewtPopupEntry *) &wifi_security); nmt_editor_grid_append(grid, _("Security"), widget, NULL); security = widget; @@ -403,4 +409,9 @@ nmt_page_wifi_class_init(NmtPageWifiClass *wifi_class) object_class->constructed = nmt_page_wifi_constructed; object_class->finalize = nmt_page_wifi_finalize; + + if (!getenv("NM_ALLOW_INSECURE_WEP")) { + wifi_security.wep[0].label = NULL; + wifi_security.wep[0].id = NULL; + } } -- cgit v1.2.1 From b46d0dcb6faa5bfd82ecad5bbbbb74ded92bda6a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 24 Aug 2022 21:49:54 +0200 Subject: libnm: undeprecate nm_remote_connection_get_secrets() Various synchronous methods (D-Bus calls) in libnm's NMClient API were deprecated. The problem is that NMClient contains a cache of D-Bus objects, and it gets updated by asynchronous events (D-Bus signals). Those events get only processed when iterating the GMainContext, but they are ordered. When we perform a pseudo blocking D-Bus call with g_dbus_connection_call_sync(), then GDBus creates a temporary GMainContext, sends the request and iterates the internal context blocking for the response. That is, this reply is not synchrounized with the events that update the NMClient cache. That is a problem for methods like nm_remote_connection_delete(), because you call blocking delete, but afterwards the object is still in the NMClient cache. That's why most blocking methods are deprecated. While such blocking calls are therefore problematic, they can still be very convenient to call from a simple script, a test tool or the python REPL. See "examples/python/gi/nm-wg-set" which calls nm_remote_connection_get_secrets(), and it would be (unnecessarily) cumbersome to do the correct thing or using async API. In particular, nm_remote_connection_get_secrets() doesn't retrieve an object that is in the NMClient cache in the first place. Sure, the result is out of order with the cache, but it's not obviously related and in most cases it wouldn't matter to the user. So undeprecate this function again. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1345 --- src/libnm-client-impl/nm-remote-connection.c | 6 +++++- src/libnm-client-public/nm-remote-connection.h | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libnm-client-impl/nm-remote-connection.c b/src/libnm-client-impl/nm-remote-connection.c index efc4dbfb94..23dfc1dac3 100644 --- a/src/libnm-client-impl/nm-remote-connection.c +++ b/src/libnm-client-impl/nm-remote-connection.c @@ -443,7 +443,11 @@ nm_remote_connection_delete_finish(NMRemoteConnection *connection, * Returns: (transfer full): a #GVariant of type %NM_VARIANT_TYPE_CONNECTION containing * @connection's secrets, or %NULL on error. * - * Deprecated: 1.22: Use nm_remote_connection_get_secrets_async() or GDBusConnection. + * Warning: NMClient contains a cache of objects on D-Bus. This cache gets updated + * with D-Bus signals when iterating the GMainContext. This function performs a + * (pseudo) blocking D-Bus call. Aside blocking, the result will not be in sync + * and not be ordered with the content of the NMClient cache. + * This function used to be deprecated between 1.22 and 1.38 releases. **/ GVariant * nm_remote_connection_get_secrets(NMRemoteConnection *connection, diff --git a/src/libnm-client-public/nm-remote-connection.h b/src/libnm-client-public/nm-remote-connection.h index f00b25d613..abfeecb367 100644 --- a/src/libnm-client-public/nm-remote-connection.h +++ b/src/libnm-client-public/nm-remote-connection.h @@ -96,7 +96,6 @@ gboolean nm_remote_connection_delete_finish(NMRemoteConnection *connection, GAsyncResult *result, GError **error); -_NM_DEPRECATED_SYNC_METHOD GVariant *nm_remote_connection_get_secrets(NMRemoteConnection *connection, const char *setting_name, GCancellable *cancellable, -- cgit v1.2.1 From 7d4307e8dfdd6c8d33d35147d593259fbaf0f7bf Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Thu, 25 Aug 2022 15:18:08 +0200 Subject: bond: fix missing assignment of lp_interval_has The variable `lp_interval` was being assigned instead of `lp_interval_has`. The `lp_interval` bond option was not being set correctly. https://bugs.launchpad.net/network-manager/+bug/1987001 Fixes: e064eb9d1361 ('bond: use netlink to set bond options') --- src/core/devices/nm-device-bond.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/devices/nm-device-bond.c b/src/core/devices/nm-device-bond.c index 41473abeca..44bb316dc4 100644 --- a/src/core/devices/nm-device-bond.c +++ b/src/core/devices/nm-device-bond.c @@ -461,7 +461,7 @@ _platform_lnk_bond_init_from_setting(NMSettingBond *s_bond, NMPlatformLnkBond *p props->peer_notif_delay_has = (props->miimon || props->arp_interval) && props->peer_notif_delay; props->arp_all_targets_has = props->arp_interval && props->arp_all_targets; props->resend_igmp_has = props->resend_igmp != 1; - props->lp_interval = props->lp_interval != 1; + props->lp_interval_has = props->lp_interval != 1; props->tlb_dynamic_lb_has = NM_IN_SET(props->mode, NM_BOND_MODE_TLB, NM_BOND_MODE_ALB); } -- cgit v1.2.1 From 5f3237acab03de4a3e9d57f50a180c5e4f6af6ca Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Thu, 25 Aug 2022 15:21:44 +0200 Subject: libnm-utils: fix typo in bond ad_select bandwidth mode The correct spelling is `bandwidth` instead of `bandwith`. https://bugs.launchpad.net/network-manager/+bug/1987001 Fixes: 32870d823379 ('libnm-utils: convert string bond opts to int') --- src/libnm-core-aux-intern/nm-libnm-core-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libnm-core-aux-intern/nm-libnm-core-utils.c b/src/libnm-core-aux-intern/nm-libnm-core-utils.c index ba05b6cd48..4fdf9d6d4e 100644 --- a/src/libnm-core-aux-intern/nm-libnm-core-utils.c +++ b/src/libnm-core-aux-intern/nm-libnm-core-utils.c @@ -51,7 +51,7 @@ NM_UTILS_STRING_TABLE_LOOKUP_DEFINE( } }, { return NM_BOND_AD_SELECT_STABLE; }, - {"bandwith", NM_BOND_AD_SELECT_BANDWIDTH}, + {"bandwidth", NM_BOND_AD_SELECT_BANDWIDTH}, {"count", NM_BOND_AD_SELECT_COUNT}, {"stable", NM_BOND_AD_SELECT_STABLE}, ); -- cgit v1.2.1 From 9b3a96f82153fc0461bbd1924c7547116193714c Mon Sep 17 00:00:00 2001 From: Wen Liang Date: Thu, 25 Aug 2022 10:54:19 -0400 Subject: dnsmasq: silently ignore if pid file is not existed when killing --- src/core/dns/nm-dns-dnsmasq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/dns/nm-dns-dnsmasq.c b/src/core/dns/nm-dns-dnsmasq.c index 7d0f0490e0..d88d3de681 100644 --- a/src/core/dns/nm-dns-dnsmasq.c +++ b/src/core/dns/nm-dns-dnsmasq.c @@ -191,7 +191,8 @@ _gl_pid_kill_external(void) if (!g_file_get_contents(PIDFILE, &contents, NULL, &error)) { if (g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) do_unlink = FALSE; - _LOGD("spawn: failure to read pidfile %s: %s", PIDFILE, error->message); + else + _LOGD("spawn: failure to read pidfile %s: %s", PIDFILE, error->message); g_clear_error(&error); goto handle_kill; } -- cgit v1.2.1 From 6058445aea1e1db0ff2369bd1b2c628063faf5e8 Mon Sep 17 00:00:00 2001 From: Wen Liang Date: Wed, 24 Aug 2022 11:39:21 -0400 Subject: dns: kill pending dnsmasq process when mode is not 'dnsmasq' When NM starts, if `main.dns` is not `dnsmasq`, then the pending dnsmasq process should be killed by NM. https://bugzilla.redhat.com/show_bug.cgi?id=2120763 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1344 --- src/core/dns/nm-dns-dnsmasq.c | 8 ++++++++ src/core/dns/nm-dns-dnsmasq.h | 2 ++ src/core/dns/nm-dns-manager.c | 3 +++ 3 files changed, 13 insertions(+) diff --git a/src/core/dns/nm-dns-dnsmasq.c b/src/core/dns/nm-dns-dnsmasq.c index d88d3de681..cc7c03a21b 100644 --- a/src/core/dns/nm-dns-dnsmasq.c +++ b/src/core/dns/nm-dns-dnsmasq.c @@ -668,6 +668,14 @@ _gl_pid_spawn(const char *dm_binary, /*****************************************************************************/ +void +nm_dnsmasq_kill_external(void) +{ + _gl_pid_kill_external(); +} + +/*****************************************************************************/ + typedef struct { GDBusConnection *dbus_connection; diff --git a/src/core/dns/nm-dns-dnsmasq.h b/src/core/dns/nm-dns-dnsmasq.h index 575b0b263f..98761d3d9f 100644 --- a/src/core/dns/nm-dns-dnsmasq.h +++ b/src/core/dns/nm-dns-dnsmasq.h @@ -25,4 +25,6 @@ GType nm_dns_dnsmasq_get_type(void); NMDnsPlugin *nm_dns_dnsmasq_new(void); +void nm_dnsmasq_kill_external(void); + #endif /* __NETWORKMANAGER_DNS_DNSMASQ_H__ */ diff --git a/src/core/dns/nm-dns-manager.c b/src/core/dns/nm-dns-manager.c index 1e54452aa4..16af1d2dfe 100644 --- a/src/core/dns/nm-dns-manager.c +++ b/src/core/dns/nm-dns-manager.c @@ -2506,6 +2506,9 @@ again: self); } + if (!NM_IS_DNS_DNSMASQ(priv->plugin)) + nm_dnsmasq_kill_external(); + _update_pending_maybe_changed(self); g_object_thaw_notify(G_OBJECT(self)); -- cgit v1.2.1 From f23e43b18a6701ec1003376a1e8b41dccc01588b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 19 Aug 2022 12:34:58 +0200 Subject: glib-aux: add "libnm-glib-aux/nm-inet-utils.h" --- Makefile.am | 2 ++ src/libnm-glib-aux/meson.build | 1 + src/libnm-glib-aux/nm-inet-utils.c | 5 +++++ src/libnm-glib-aux/nm-inet-utils.h | 6 ++++++ 4 files changed, 14 insertions(+) create mode 100644 src/libnm-glib-aux/nm-inet-utils.c create mode 100644 src/libnm-glib-aux/nm-inet-utils.h diff --git a/Makefile.am b/Makefile.am index 109326c309..1a6b756a61 100644 --- a/Makefile.am +++ b/Makefile.am @@ -423,6 +423,8 @@ src_libnm_glib_aux_libnm_glib_aux_la_SOURCES = \ src/libnm-glib-aux/nm-glib.h \ src/libnm-glib-aux/nm-hash-utils.c \ src/libnm-glib-aux/nm-hash-utils.h \ + src/libnm-glib-aux/nm-inet-utils.c \ + src/libnm-glib-aux/nm-inet-utils.h \ src/libnm-glib-aux/nm-io-utils.c \ src/libnm-glib-aux/nm-io-utils.h \ src/libnm-glib-aux/nm-jansson.h \ diff --git a/src/libnm-glib-aux/meson.build b/src/libnm-glib-aux/meson.build index 4f13fd0b17..d5e88e6b7a 100644 --- a/src/libnm-glib-aux/meson.build +++ b/src/libnm-glib-aux/meson.build @@ -8,6 +8,7 @@ libnm_glib_aux = static_library( 'nm-enum-utils.c', 'nm-errno.c', 'nm-hash-utils.c', + 'nm-inet-utils.c', 'nm-io-utils.c', 'nm-json-aux.c', 'nm-keyfile-aux.c', diff --git a/src/libnm-glib-aux/nm-inet-utils.c b/src/libnm-glib-aux/nm-inet-utils.c new file mode 100644 index 0000000000..9e79af2050 --- /dev/null +++ b/src/libnm-glib-aux/nm-inet-utils.c @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "libnm-glib-aux/nm-default-glib-i18n-lib.h" + +#include "nm-inet-utils.h" diff --git a/src/libnm-glib-aux/nm-inet-utils.h b/src/libnm-glib-aux/nm-inet-utils.h new file mode 100644 index 0000000000..3314c9d191 --- /dev/null +++ b/src/libnm-glib-aux/nm-inet-utils.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#ifndef __NM_INET_UTILS_H__ +#define __NM_INET_UTILS_H__ + +#endif /* __NM_INET_UTILS_H__ */ -- cgit v1.2.1 From d65feb26e53bb6442f2a61cd97ad70bc3b9aad4b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 19 Aug 2022 12:36:56 +0200 Subject: glib-aux: move inet related helpers to "nm-inet-utils.h" --- src/libnm-glib-aux/nm-default-glib.h | 1 + src/libnm-glib-aux/nm-inet-utils.c | 526 +++++++++++++++++++++++++++++++++++ src/libnm-glib-aux/nm-inet-utils.h | 366 ++++++++++++++++++++++++ src/libnm-glib-aux/nm-shared-utils.c | 521 ---------------------------------- src/libnm-glib-aux/nm-shared-utils.h | 365 +----------------------- 5 files changed, 897 insertions(+), 882 deletions(-) diff --git a/src/libnm-glib-aux/nm-default-glib.h b/src/libnm-glib-aux/nm-default-glib.h index f39e16cc5b..18460de8ff 100644 --- a/src/libnm-glib-aux/nm-default-glib.h +++ b/src/libnm-glib-aux/nm-default-glib.h @@ -67,6 +67,7 @@ #include "libnm-glib-aux/nm-shared-utils.h" #include "libnm-glib-aux/nm-errno.h" #include "libnm-glib-aux/nm-hash-utils.h" +#include "libnm-glib-aux/nm-inet-utils.h" /*****************************************************************************/ diff --git a/src/libnm-glib-aux/nm-inet-utils.c b/src/libnm-glib-aux/nm-inet-utils.c index 9e79af2050..46fd07ddb5 100644 --- a/src/libnm-glib-aux/nm-inet-utils.c +++ b/src/libnm-glib-aux/nm-inet-utils.c @@ -3,3 +3,529 @@ #include "libnm-glib-aux/nm-default-glib-i18n-lib.h" #include "nm-inet-utils.h" + +#include +#include + +/*****************************************************************************/ + +const NMIPAddr nm_ip_addr_zero = {}; + +/* We use _nm_alignas(NMIPAddr) to ensure that fields for in_addr_t and + * struct in6_addr have all the same alignment. Ensure that this is suitable. */ +G_STATIC_ASSERT(_nm_alignof(in_addr_t) <= _nm_alignof(NMIPAddr)); +G_STATIC_ASSERT(_nm_alignof(struct in_addr) <= _nm_alignof(NMIPAddr)); +G_STATIC_ASSERT(_nm_alignof(struct in6_addr) <= _nm_alignof(NMIPAddr)); +G_STATIC_ASSERT(_nm_alignof(NMEtherAddr) <= _nm_alignof(NMIPAddr)); + +int +nm_ip_addr_cmp_for_sort(gconstpointer a, gconstpointer b, gpointer user_data) +{ + /* This is a compare function that can be used for sorting IP addresses. + * Essentially, it calls memcmp(). @user_data must be GINT_TO_POINTER(addr_family). + * @a and @b must be either pointers to in_addr_t, struct in6_addr or NMIPAddr. */ + return nm_ip_addr_cmp(GPOINTER_TO_INT(user_data), a, b); +} + +/* this initializes a struct in_addr/in6_addr and allows for untrusted + * arguments (like unsuitable @addr_family or @src_len). It's almost safe + * in the sense that it verifies input arguments strictly. Also, it + * uses memcpy() to access @src, so alignment is not an issue. + * + * Only potential pitfalls: + * + * - it allows for @addr_family to be AF_UNSPEC. If that is the case (and the + * caller allows for that), the caller MUST provide @out_addr_family. + * - when setting @dst to an IPv4 address, the trailing bytes are not touched. + * Meaning, if @dst is an NMIPAddr union, only the first bytes will be set. + * If that matter to you, clear @dst before. */ +gboolean +nm_ip_addr_set_from_untrusted(int addr_family, + gpointer dst, + gconstpointer src, + gsize src_len, + int *out_addr_family) +{ + nm_assert(dst); + + switch (addr_family) { + case AF_UNSPEC: + if (!out_addr_family) { + /* when the callers allow undefined @addr_family, they must provide + * an @out_addr_family argument. */ + nm_assert_not_reached(); + return FALSE; + } + switch (src_len) { + case sizeof(struct in_addr): + addr_family = AF_INET; + break; + case sizeof(struct in6_addr): + addr_family = AF_INET6; + break; + default: + return FALSE; + } + break; + case AF_INET: + if (src_len != sizeof(struct in_addr)) + return FALSE; + break; + case AF_INET6: + if (src_len != sizeof(struct in6_addr)) + return FALSE; + break; + default: + /* when the callers allow undefined @addr_family, they must provide + * an @out_addr_family argument. */ + nm_assert(out_addr_family); + return FALSE; + } + + nm_assert(src); + + memcpy(dst, src, src_len); + NM_SET_OUT(out_addr_family, addr_family); + return TRUE; +} + +gboolean +nm_ip_addr_set_from_variant(int addr_family, gpointer dst, GVariant *variant, int *out_addr_family) +{ + gconstpointer bytes; + gsize len; + + g_return_val_if_fail(dst, FALSE); + g_return_val_if_fail(variant, FALSE); + + /* This function always expects IP addressea a byte arrays ("ay"). Note that + * several NetworkManager API uses "u" (32 bit unsigned intergers) for IPv4 addresses. + * So this function won't work in those cases. + * + * Btw, using "u" for IPv4 address messes badly with the endianness (host + * vs network byte order). Don't do that. + */ + g_return_val_if_fail(g_variant_is_of_type(variant, G_VARIANT_TYPE("ay")), FALSE); + + bytes = g_variant_get_fixed_array(variant, &len, sizeof(guint8)); + + return nm_ip_addr_set_from_untrusted(addr_family, dst, bytes, len, out_addr_family); +} + +/*****************************************************************************/ + +guint32 +_nm_utils_ip4_get_default_prefix0(in_addr_t ip) +{ + /* The function is originally from ipcalc.c of Red Hat's initscripts. */ + switch (ntohl(ip) >> 24) { + case 0 ... 127: + return 8; /* Class A */ + case 128 ... 191: + return 16; /* Class B */ + case 192 ... 223: + return 24; /* Class C */ + } + return 0; +} + +guint32 +_nm_utils_ip4_get_default_prefix(in_addr_t ip) +{ + return _nm_utils_ip4_get_default_prefix0(ip) ?: 24; +} + +gboolean +nm_utils_ip_is_site_local(int addr_family, const void *address) +{ + in_addr_t addr4; + + switch (addr_family) { + case AF_INET: + /* RFC1918 private addresses + * 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 */ + addr4 = ntohl(*((const in_addr_t *) address)); + return (addr4 & 0xff000000) == 0x0a000000 || (addr4 & 0xfff00000) == 0xac100000 + || (addr4 & 0xffff0000) == 0xc0a80000; + case AF_INET6: + /* IN6_IS_ADDR_SITELOCAL() is for deprecated fec0::/10 addresses (see rfc3879, 4.). + * Note that for unique local IPv6 addresses (ULA, fc00::/7) this returns false, + * which may or may not be a bug. */ + return IN6_IS_ADDR_SITELOCAL(address); + default: + g_return_val_if_reached(FALSE); + } +} + +gboolean +nm_utils_ip6_is_ula(const struct in6_addr *address) +{ + /* Unique local IPv6 address (ULA) fc00::/7 */ + return (address->s6_addr32[0] & htonl(0xfe000000u)) == htonl(0xfc000000u); +} + +/*****************************************************************************/ + +gconstpointer +nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint32 plen) +{ + g_return_val_if_fail(dst, NULL); + + switch (family) { + case AF_INET: + g_return_val_if_fail(plen <= 32, NULL); + + if (!src) { + /* allow "self-assignment", by specifying %NULL as source. */ + src = dst; + } + + *((guint32 *) dst) = nm_utils_ip4_address_clear_host_address(*((guint32 *) src), plen); + break; + case AF_INET6: + nm_utils_ip6_address_clear_host_address(dst, src, plen); + break; + default: + g_return_val_if_reached(NULL); + } + return dst; +} + +/* nm_utils_ip6_address_clear_host_address: + * @dst: destination output buffer, will contain the network part of the @src address + * @src: source ip6 address. If NULL, this does an in-place update of @dst. + * Also, @src and @dst are allowed to be the same pointers. + * @plen: prefix length of network + * + * Note: this function is self assignment safe, to update @src inplace, set both + * @dst and @src to the same destination or set @src NULL. + */ +const struct in6_addr * +nm_utils_ip6_address_clear_host_address(struct in6_addr *dst, + const struct in6_addr *src, + guint32 plen) +{ + g_return_val_if_fail(plen <= 128, NULL); + g_return_val_if_fail(dst, NULL); + + if (!src) + src = dst; + + if (plen < 128) { + guint nbytes = plen / 8; + guint nbits = plen % 8; + + if (nbytes && dst != src) + memcpy(dst, src, nbytes); + if (nbits) { + dst->s6_addr[nbytes] = (src->s6_addr[nbytes] & (0xFF << (8 - nbits))); + nbytes++; + } + if (nbytes <= 15) + memset(&dst->s6_addr[nbytes], 0, 16 - nbytes); + } else if (src != dst) + *dst = *src; + + return dst; +} + +int +nm_utils_ip6_address_same_prefix_cmp(const struct in6_addr *addr_a, + const struct in6_addr *addr_b, + guint32 plen) +{ + int nbytes; + guint8 va, vb, m; + + if (plen >= 128) { + nm_assert(plen == 128); + NM_CMP_DIRECT_MEMCMP(addr_a, addr_b, sizeof(struct in6_addr)); + } else { + nbytes = plen / 8; + if (nbytes) + NM_CMP_DIRECT_MEMCMP(addr_a, addr_b, nbytes); + + plen = plen % 8; + if (plen != 0) { + m = ~((1 << (8 - plen)) - 1); + va = ((((const guint8 *) addr_a))[nbytes]) & m; + vb = ((((const guint8 *) addr_b))[nbytes]) & m; + NM_CMP_DIRECT(va, vb); + } + } + return 0; +} + +/*****************************************************************************/ + +static gboolean +_parse_legacy_addr4(const char *text, in_addr_t *out_addr, GError **error) +{ + gs_free char *s_free = NULL; + struct in_addr a1; + guint8 bin[sizeof(a1)]; + char *s; + int i; + + if (inet_aton(text, &a1) != 1) { + g_set_error_literal(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + "address invalid according to inet_aton()"); + return FALSE; + } + + /* OK, inet_aton() accepted the format. That's good, because we want + * to accept IPv4 addresses in octal format, like 255.255.000.000. + * That's what "legacy" means here. inet_pton() doesn't accept those. + * + * But inet_aton() also ignores trailing garbage and formats with fewer than + * 4 digits. That is just too crazy and we don't do that. Perform additional checks + * and reject some forms that inet_aton() accepted. + * + * Note that we still should (of course) accept everything that inet_pton() + * accepts. However this code never gets called if inet_pton() succeeds + * (see below, aside the assertion code). */ + + if (NM_STRCHAR_ANY(text, ch, (!(ch >= '0' && ch <= '9') && !NM_IN_SET(ch, '.', 'x')))) { + /* We only accepts '.', digits, and 'x' for "0x". */ + g_set_error_literal(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + "contains an invalid character"); + return FALSE; + } + + s = nm_memdup_maybe_a(300, text, strlen(text) + 1, &s_free); + + for (i = 0; i < G_N_ELEMENTS(bin); i++) { + char *current_token = s; + gint32 v; + + s = strchr(s, '.'); + if (s) { + s[0] = '\0'; + s++; + } + + if ((i == G_N_ELEMENTS(bin) - 1) != (s == NULL)) { + /* Exactly for the last digit, we expect to have no more following token. + * But this isn't the case. Abort. */ + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + "wrong number of tokens (index %d, token '%s')", + i, + s); + return FALSE; + } + + v = _nm_utils_ascii_str_to_int64(current_token, 0, 0, 0xFF, -1); + if (v == -1) { + int errsv = errno; + + /* we do accept octal and hex (even with leading "0x"). But something + * about this token is wrong. */ + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + "invalid token '%s': %s (%d)", + current_token, + nm_strerror_native(errsv), + errsv); + return FALSE; + } + + bin[i] = v; + } + + if (memcmp(bin, &a1, sizeof(bin)) != 0) { + /* our parsing did not agree with what inet_aton() gave. Something + * is wrong. Abort. */ + g_set_error( + error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + "inet_aton() result 0x%08x differs from computed value 0x%02hhx%02hhx%02hhx%02hhx", + a1.s_addr, + bin[0], + bin[1], + bin[2], + bin[3]); + return FALSE; + } + + *out_addr = a1.s_addr; + return TRUE; +} + +gboolean +nm_utils_parse_inaddr_bin_full(int addr_family, + gboolean accept_legacy, + const char *text, + int *out_addr_family, + gpointer out_addr) +{ + NMIPAddr addrbin; + + g_return_val_if_fail(text, FALSE); + + if (addr_family == AF_UNSPEC) { + g_return_val_if_fail(!out_addr || out_addr_family, FALSE); + addr_family = strchr(text, ':') ? AF_INET6 : AF_INET; + } else + g_return_val_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6), FALSE); + + if (inet_pton(addr_family, text, &addrbin) != 1) { + if (accept_legacy && addr_family == AF_INET + && _parse_legacy_addr4(text, &addrbin.addr4, NULL)) { + /* The address is in some legacy format which inet_aton() accepts, but not inet_pton(). + * Most likely octal digits (leading zeros). We accept the address. */ + } else + return FALSE; + } + +#if NM_MORE_ASSERTS > 10 + if (addr_family == AF_INET) { + NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER + gs_free_error GError *error = NULL; + in_addr_t a; + + /* The legacy parser should accept everything that inet_pton() accepts too. Meaning, + * it should strictly parse *more* formats. And of course, parse it the same way. */ + if (!_parse_legacy_addr4(text, &a, &error)) { + char buf[INET_ADDRSTRLEN]; + + g_error("unexpected assertion failure: could parse \"%s\" as %s, but not accepted by " + "legacy parser: %s", + text, + _nm_utils_inet4_ntop(addrbin.addr4, buf), + error->message); + } + nm_assert(addrbin.addr4 == a); + NM_PRAGMA_WARNING_REENABLE + } +#endif + + NM_SET_OUT(out_addr_family, addr_family); + if (out_addr) + nm_ip_addr_set(addr_family, out_addr, &addrbin); + return TRUE; +} + +gboolean +nm_utils_parse_inaddr(int addr_family, const char *text, char **out_addr) +{ + NMIPAddr addrbin; + char addrstr_buf[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)]; + + g_return_val_if_fail(text, FALSE); + + if (addr_family == AF_UNSPEC) + addr_family = strchr(text, ':') ? AF_INET6 : AF_INET; + else + g_return_val_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6), FALSE); + + if (inet_pton(addr_family, text, &addrbin) != 1) + return FALSE; + + NM_SET_OUT(out_addr, + g_strdup(inet_ntop(addr_family, &addrbin, addrstr_buf, sizeof(addrstr_buf)))); + return TRUE; +} + +gboolean +nm_utils_parse_inaddr_prefix_bin(int addr_family, + const char *text, + int *out_addr_family, + gpointer out_addr, + int *out_prefix) +{ + gs_free char *addrstr_free = NULL; + int prefix = -1; + const char *slash; + const char *addrstr; + NMIPAddr addrbin; + + g_return_val_if_fail(text, FALSE); + + if (addr_family == AF_UNSPEC) { + g_return_val_if_fail(!out_addr || out_addr_family, FALSE); + addr_family = strchr(text, ':') ? AF_INET6 : AF_INET; + } else + g_return_val_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6), FALSE); + + slash = strchr(text, '/'); + if (slash) + addrstr = nm_strndup_a(300, text, slash - text, &addrstr_free); + else + addrstr = text; + + if (inet_pton(addr_family, addrstr, &addrbin) != 1) + return FALSE; + + if (slash) { + /* For IPv4, `ip addr add` supports the prefix-length as a netmask. We don't + * do that. */ + prefix = + _nm_utils_ascii_str_to_int64(&slash[1], 10, 0, addr_family == AF_INET ? 32 : 128, -1); + if (prefix == -1) + return FALSE; + } + + NM_SET_OUT(out_addr_family, addr_family); + if (out_addr) + nm_ip_addr_set(addr_family, out_addr, &addrbin); + NM_SET_OUT(out_prefix, prefix); + return TRUE; +} + +gboolean +nm_utils_parse_inaddr_prefix(int addr_family, const char *text, char **out_addr, int *out_prefix) +{ + NMIPAddr addrbin; + char addrstr_buf[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)]; + + if (!nm_utils_parse_inaddr_prefix_bin(addr_family, text, &addr_family, &addrbin, out_prefix)) + return FALSE; + NM_SET_OUT(out_addr, + g_strdup(inet_ntop(addr_family, &addrbin, addrstr_buf, sizeof(addrstr_buf)))); + return TRUE; +} + +/*****************************************************************************/ + +gboolean +nm_utils_ipaddr_is_valid(int addr_family, const char *str_addr) +{ + nm_assert(NM_IN_SET(addr_family, AF_UNSPEC, AF_INET, AF_INET6)); + + return str_addr && nm_utils_parse_inaddr_bin(addr_family, str_addr, NULL, NULL); +} + +gboolean +nm_utils_ipaddr_is_normalized(int addr_family, const char *str_addr) +{ + NMIPAddr addr; + char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + + nm_assert(NM_IN_SET(addr_family, AF_UNSPEC, AF_INET, AF_INET6)); + + if (!str_addr) + return FALSE; + + if (!nm_utils_parse_inaddr_bin(addr_family, str_addr, &addr_family, &addr)) + return FALSE; + + nm_utils_inet_ntop(addr_family, &addr, sbuf); + return nm_streq(sbuf, str_addr); +} + +/*****************************************************************************/ + +NM_UTILS_ENUM2STR_DEFINE(nm_icmpv6_router_pref_to_string, + NMIcmpv6RouterPref, + NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_LOW, "low"), + NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_MEDIUM, "medium"), + NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_HIGH, "high"), + NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_INVALID, "invalid"), ); diff --git a/src/libnm-glib-aux/nm-inet-utils.h b/src/libnm-glib-aux/nm-inet-utils.h index 3314c9d191..ffb7f4ab0a 100644 --- a/src/libnm-glib-aux/nm-inet-utils.h +++ b/src/libnm-glib-aux/nm-inet-utils.h @@ -3,4 +3,370 @@ #ifndef __NM_INET_UTILS_H__ #define __NM_INET_UTILS_H__ +typedef struct _NMIPAddr { + union { + guint8 addr_ptr[sizeof(struct in6_addr)]; + in_addr_t addr4; + struct in_addr addr4_struct; + struct in6_addr addr6; + + /* NMIPAddr is really a union for IP addresses. + * However, as ethernet addresses fit in here nicely, use + * it also for an ethernet MAC address. */ + guint8 ether_addr_octet[6 /*ETH_ALEN*/]; + NMEtherAddr ether_addr; + + guint8 array[sizeof(struct in6_addr)]; + }; +} NMIPAddr; + +#define NM_IP_ADDR_INIT \ + { \ + .array = { 0 } \ + } + +extern const NMIPAddr nm_ip_addr_zero; + +/* This doesn't really belong here, but since it's convenient to re-use nm_ip_addr_zero.ether_addr + * for NMEtherAddr, it is. */ +#define nm_ether_addr_zero (nm_ip_addr_zero.ether_addr) + +static inline int +nm_ip_addr_cmp(int addr_family, gconstpointer a, gconstpointer b) +{ + /* Note that @a and @b are not required to be full NMIPAddr unions. + * Depending on @addr_family, they can also be only in_addr_t or + * struct in6_addr. */ + NM_CMP_SELF(a, b); + NM_CMP_DIRECT_MEMCMP(a, b, nm_utils_addr_family_to_size(addr_family)); + return 0; +} + +int nm_ip_addr_cmp_for_sort(gconstpointer a, gconstpointer b, gpointer user_data); + +static inline gboolean +nm_ip_addr_equal(int addr_family, gconstpointer a, gconstpointer b) +{ + return nm_ip_addr_cmp(addr_family, a, b) == 0; +} + +static inline gboolean +nm_ip_addr_is_null(int addr_family, gconstpointer addr) +{ + nm_assert(addr); + + if (NM_IS_IPv4(addr_family)) { + in_addr_t t; + + /* also for in_addr_t type (AF_INET), we accept that the pointer might + * be unaligned. */ + memcpy(&t, addr, sizeof(t)); + return t == 0; + } + + return IN6_IS_ADDR_UNSPECIFIED((const struct in6_addr *) addr); +} + +static inline void +nm_ip_addr_set(int addr_family, gpointer dst, gconstpointer src) +{ + nm_assert(dst); + nm_assert(src); + + /* this MUST use memcpy() to support unaligned src/dst pointers. */ + memcpy(dst, src, nm_utils_addr_family_to_size(addr_family)); + + /* Note that @dst is not necessarily a NMIPAddr, it could also be just + * an in_addr_t/struct in6_addr. We thus can only set the bytes that + * we know are present based on the address family. + * + * Using this function to initialize an NMIPAddr union (for IPv4) leaves + * uninitalized bytes. Avoid that by using nm_ip_addr_init() instead. */ +} + +static inline NMIPAddr +nm_ip_addr_init(int addr_family, gconstpointer src) +{ + NMIPAddr a; + + nm_assert_addr_family(addr_family); + nm_assert(src); + + G_STATIC_ASSERT_EXPR(sizeof(NMIPAddr) == sizeof(struct in6_addr)); + + /* this MUST use memcpy() to support unaligned src/dst pointers. */ + + if (NM_IS_IPv4(addr_family)) { + memcpy(&a, src, sizeof(in_addr_t)); + + /* ensure all bytes of the union are initialized. If only to make + * valgrind happy. */ + memset(&a.array[sizeof(in_addr_t)], 0, sizeof(a) - sizeof(in_addr_t)); + } else + memcpy(&a, src, sizeof(struct in6_addr)); + + return a; +} + +gboolean nm_ip_addr_set_from_untrusted(int addr_family, + gpointer dst, + gconstpointer src, + gsize src_len, + int *out_addr_family); + +gboolean +nm_ip_addr_set_from_variant(int addr_family, gpointer dst, GVariant *variant, int *out_addr_family); + +static inline gconstpointer +nm_ip_addr_from_packed_array(int addr_family, gconstpointer ipaddr_arr, gsize idx) +{ + return NM_IS_IPv4(addr_family) + ? ((gconstpointer) & (((const struct in_addr *) ipaddr_arr)[idx])) + : ((gconstpointer) & (((const struct in6_addr *) ipaddr_arr)[idx])); +} + +/*****************************************************************************/ + +static inline guint32 +_nm_utils_ip4_netmask_to_prefix(in_addr_t subnetmask) +{ + G_STATIC_ASSERT_EXPR(__SIZEOF_INT__ == 4); + G_STATIC_ASSERT_EXPR(sizeof(int) == 4); + G_STATIC_ASSERT_EXPR(sizeof(guint) == 4); + G_STATIC_ASSERT_EXPR(sizeof(subnetmask) == 4); + + return ((subnetmask != 0u) ? (guint32) (32 - __builtin_ctz(ntohl(subnetmask))) : 0u); +} + +/** + * _nm_utils_ip4_prefix_to_netmask: + * @prefix: a CIDR prefix + * + * Returns: the netmask represented by the prefix, in network byte order + **/ +static inline in_addr_t +_nm_utils_ip4_prefix_to_netmask(guint32 prefix) +{ + nm_assert(prefix <= 32); + return prefix < 32 ? ~htonl(0xFFFFFFFFu >> prefix) : 0xFFFFFFFFu; +} + +guint32 _nm_utils_ip4_get_default_prefix0(in_addr_t ip); +guint32 _nm_utils_ip4_get_default_prefix(in_addr_t ip); + +gconstpointer +nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint32 plen); + +/* nm_utils_ip4_address_clear_host_address: + * @addr: source ip6 address + * @plen: prefix length of network + * + * returns: the input address, with the host address set to 0. + */ +static inline in_addr_t +nm_utils_ip4_address_clear_host_address(in_addr_t addr, guint32 plen) +{ + return addr & _nm_utils_ip4_prefix_to_netmask(plen); +} + +const struct in6_addr *nm_utils_ip6_address_clear_host_address(struct in6_addr *dst, + const struct in6_addr *src, + guint32 plen); + +/*****************************************************************************/ + +static inline int +nm_utils_ip4_address_same_prefix_cmp(in_addr_t addr_a, in_addr_t addr_b, guint32 plen) +{ + NM_CMP_DIRECT(htonl(nm_utils_ip4_address_clear_host_address(addr_a, plen)), + htonl(nm_utils_ip4_address_clear_host_address(addr_b, plen))); + return 0; +} + +int nm_utils_ip6_address_same_prefix_cmp(const struct in6_addr *addr_a, + const struct in6_addr *addr_b, + guint32 plen); + +static inline gboolean +nm_utils_ip4_address_same_prefix(in_addr_t addr_a, in_addr_t addr_b, guint32 plen) +{ + return nm_utils_ip4_address_same_prefix_cmp(addr_a, addr_b, plen) == 0; +} + +static inline gboolean +nm_utils_ip6_address_same_prefix(const struct in6_addr *addr_a, + const struct in6_addr *addr_b, + guint8 plen) +{ + return nm_utils_ip6_address_same_prefix_cmp(addr_a, addr_b, plen) == 0; +} + +static inline int +nm_utils_ip_address_same_prefix_cmp(int addr_family, + gconstpointer addr_a, + gconstpointer addr_b, + guint8 plen) +{ + NM_CMP_SELF(addr_a, addr_b); + + if (NM_IS_IPv4(addr_family)) { + return nm_utils_ip4_address_same_prefix_cmp(*((const in_addr_t *) addr_a), + *((const in_addr_t *) addr_b), + plen); + } + + return nm_utils_ip6_address_same_prefix_cmp(addr_a, addr_b, plen); +} + +static inline gboolean +nm_utils_ip_address_same_prefix(int addr_family, + gconstpointer addr_a, + gconstpointer addr_b, + guint8 plen) +{ + return nm_utils_ip_address_same_prefix_cmp(addr_family, addr_a, addr_b, plen) == 0; +} + +#define NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX(a, b, plen) \ + NM_CMP_RETURN(nm_utils_ip4_address_same_prefix_cmp((a), (b), (plen))) + +#define NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX(a, b, plen) \ + NM_CMP_RETURN(nm_utils_ip6_address_same_prefix_cmp((a), (b), (plen))) + +/*****************************************************************************/ + +gboolean nm_utils_ip_is_site_local(int addr_family, const void *address); +gboolean nm_utils_ip6_is_ula(const struct in6_addr *address); + +/*****************************************************************************/ + +#define NM_IPV4LL_NETWORK ((in_addr_t) htonl(0xA9FE0000lu)) +#define NM_IPV4LL_NETMASK ((in_addr_t) htonl(0xFFFF0000lu)) + +static inline gboolean +nm_utils_ip4_address_is_loopback(in_addr_t addr) +{ + /* There is also IN_LOOPBACK() in , but there the + * argument is in host order not `in_addr_t`. */ + return (addr & htonl(0xFF000000u)) == htonl(0x7F000000u); +} + +static inline gboolean +nm_utils_ip4_address_is_link_local(in_addr_t addr) +{ + return (addr & NM_IPV4LL_NETMASK) == NM_IPV4LL_NETWORK; +} + +static inline gboolean +nm_utils_ip4_address_is_zeronet(in_addr_t network) +{ + /* Same as ipv4_is_zeronet() from kernel's include/linux/in.h. */ + return (network & htonl(0xFF000000u)) == htonl(0x00000000u); +} + +/*****************************************************************************/ + +#define NM_UTILS_INET_ADDRSTRLEN INET6_ADDRSTRLEN + +/* Forward declare function so we don't have to drag in . */ +const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); + +static inline const char * +nm_utils_inet_ntop(int addr_family, gconstpointer addr, char *dst) +{ + const char *s; + + nm_assert_addr_family(addr_family); + nm_assert(addr); + nm_assert(dst); + + s = inet_ntop(addr_family, + addr, + dst, + addr_family == AF_INET6 ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN); + nm_assert(s); + return s; +} + +static inline const char * +_nm_utils_inet4_ntop(in_addr_t addr, char dst[static INET_ADDRSTRLEN]) +{ + return nm_utils_inet_ntop(AF_INET, &addr, dst); +} + +static inline const char * +_nm_utils_inet6_ntop(const struct in6_addr *addr, char dst[static INET6_ADDRSTRLEN]) +{ + return nm_utils_inet_ntop(AF_INET6, addr, dst); +} + +static inline char * +nm_utils_inet_ntop_dup(int addr_family, gconstpointer addr) +{ + char buf[NM_UTILS_INET_ADDRSTRLEN]; + + return g_strdup(nm_utils_inet_ntop(addr_family, addr, buf)); +} + +static inline char * +nm_utils_inet4_ntop_dup(in_addr_t addr) +{ + return nm_utils_inet_ntop_dup(AF_INET, &addr); +} + +static inline char * +nm_utils_inet6_ntop_dup(const struct in6_addr *addr) +{ + return nm_utils_inet_ntop_dup(AF_INET6, addr); +} + +/*****************************************************************************/ + +gboolean nm_utils_parse_inaddr_bin_full(int addr_family, + gboolean accept_legacy, + const char *text, + int *out_addr_family, + gpointer out_addr); +static inline gboolean +nm_utils_parse_inaddr_bin(int addr_family, + const char *text, + int *out_addr_family, + gpointer out_addr) +{ + return nm_utils_parse_inaddr_bin_full(addr_family, FALSE, text, out_addr_family, out_addr); +} + +gboolean nm_utils_parse_inaddr(int addr_family, const char *text, char **out_addr); + +gboolean nm_utils_parse_inaddr_prefix_bin(int addr_family, + const char *text, + int *out_addr_family, + gpointer out_addr, + int *out_prefix); + +gboolean +nm_utils_parse_inaddr_prefix(int addr_family, const char *text, char **out_addr, int *out_prefix); + +/*****************************************************************************/ + +gboolean nm_utils_ipaddr_is_valid(int addr_family, const char *str_addr); + +gboolean nm_utils_ipaddr_is_normalized(int addr_family, const char *str_addr); + +/*****************************************************************************/ + +/* this enum is compatible with ICMPV6_ROUTER_PREF_* (from , + * the values for netlink attribute RTA_PREF) and "enum ndp_route_preference" + * from . */ +typedef enum _nm_packed { + NM_ICMPV6_ROUTER_PREF_MEDIUM = 0x0, /* ICMPV6_ROUTER_PREF_MEDIUM */ + NM_ICMPV6_ROUTER_PREF_LOW = 0x3, /* ICMPV6_ROUTER_PREF_LOW */ + NM_ICMPV6_ROUTER_PREF_HIGH = 0x1, /* ICMPV6_ROUTER_PREF_HIGH */ + NM_ICMPV6_ROUTER_PREF_INVALID = 0x2, /* ICMPV6_ROUTER_PREF_INVALID */ +} NMIcmpv6RouterPref; + +const char *nm_icmpv6_router_pref_to_string(NMIcmpv6RouterPref pref, char *buf, gsize len); + +/*****************************************************************************/ + #endif /* __NM_INET_UTILS_H__ */ diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c index 624f9a3e97..057fc0f389 100644 --- a/src/libnm-glib-aux/nm-shared-utils.c +++ b/src/libnm-glib-aux/nm-shared-utils.c @@ -35,111 +35,6 @@ const void *const _NM_PTRARRAY_EMPTY[1] = {NULL}; /*****************************************************************************/ -const NMIPAddr nm_ip_addr_zero = {}; - -/* We use _nm_alignas(NMIPAddr) to ensure that fields for in_addr_t and - * struct in6_addr have all the same alignment. Ensure that this is suitable. */ -G_STATIC_ASSERT(_nm_alignof(in_addr_t) <= _nm_alignof(NMIPAddr)); -G_STATIC_ASSERT(_nm_alignof(struct in_addr) <= _nm_alignof(NMIPAddr)); -G_STATIC_ASSERT(_nm_alignof(struct in6_addr) <= _nm_alignof(NMIPAddr)); -G_STATIC_ASSERT(_nm_alignof(NMEtherAddr) <= _nm_alignof(NMIPAddr)); - -int -nm_ip_addr_cmp_for_sort(gconstpointer a, gconstpointer b, gpointer user_data) -{ - /* This is a compare function that can be used for sorting IP addresses. - * Essentially, it calls memcmp(). @user_data must be GINT_TO_POINTER(addr_family). - * @a and @b must be either pointers to in_addr_t, struct in6_addr or NMIPAddr. */ - return nm_ip_addr_cmp(GPOINTER_TO_INT(user_data), a, b); -} - -/* this initializes a struct in_addr/in6_addr and allows for untrusted - * arguments (like unsuitable @addr_family or @src_len). It's almost safe - * in the sense that it verifies input arguments strictly. Also, it - * uses memcpy() to access @src, so alignment is not an issue. - * - * Only potential pitfalls: - * - * - it allows for @addr_family to be AF_UNSPEC. If that is the case (and the - * caller allows for that), the caller MUST provide @out_addr_family. - * - when setting @dst to an IPv4 address, the trailing bytes are not touched. - * Meaning, if @dst is an NMIPAddr union, only the first bytes will be set. - * If that matter to you, clear @dst before. */ -gboolean -nm_ip_addr_set_from_untrusted(int addr_family, - gpointer dst, - gconstpointer src, - gsize src_len, - int *out_addr_family) -{ - nm_assert(dst); - - switch (addr_family) { - case AF_UNSPEC: - if (!out_addr_family) { - /* when the callers allow undefined @addr_family, they must provide - * an @out_addr_family argument. */ - nm_assert_not_reached(); - return FALSE; - } - switch (src_len) { - case sizeof(struct in_addr): - addr_family = AF_INET; - break; - case sizeof(struct in6_addr): - addr_family = AF_INET6; - break; - default: - return FALSE; - } - break; - case AF_INET: - if (src_len != sizeof(struct in_addr)) - return FALSE; - break; - case AF_INET6: - if (src_len != sizeof(struct in6_addr)) - return FALSE; - break; - default: - /* when the callers allow undefined @addr_family, they must provide - * an @out_addr_family argument. */ - nm_assert(out_addr_family); - return FALSE; - } - - nm_assert(src); - - memcpy(dst, src, src_len); - NM_SET_OUT(out_addr_family, addr_family); - return TRUE; -} - -gboolean -nm_ip_addr_set_from_variant(int addr_family, gpointer dst, GVariant *variant, int *out_addr_family) -{ - gconstpointer bytes; - gsize len; - - g_return_val_if_fail(dst, FALSE); - g_return_val_if_fail(variant, FALSE); - - /* This function always expects IP addressea a byte arrays ("ay"). Note that - * several NetworkManager API uses "u" (32 bit unsigned intergers) for IPv4 addresses. - * So this function won't work in those cases. - * - * Btw, using "u" for IPv4 address messes badly with the endianness (host - * vs network byte order). Don't do that. - */ - g_return_val_if_fail(g_variant_is_of_type(variant, G_VARIANT_TYPE("ay")), FALSE); - - bytes = g_variant_get_fixed_array(variant, &len, sizeof(guint8)); - - return nm_ip_addr_set_from_untrusted(addr_family, dst, bytes, len, out_addr_family); -} - -/*****************************************************************************/ - G_STATIC_ASSERT(ETH_ALEN == sizeof(struct ether_addr)); G_STATIC_ASSERT(ETH_ALEN == 6); G_STATIC_ASSERT(ETH_ALEN == sizeof(NMEtherAddr)); @@ -981,293 +876,6 @@ nm_utils_flags2str(const NMUtilsFlags2StrDesc *descs, /*****************************************************************************/ -guint32 -_nm_utils_ip4_get_default_prefix0(in_addr_t ip) -{ - /* The function is originally from ipcalc.c of Red Hat's initscripts. */ - switch (ntohl(ip) >> 24) { - case 0 ... 127: - return 8; /* Class A */ - case 128 ... 191: - return 16; /* Class B */ - case 192 ... 223: - return 24; /* Class C */ - } - return 0; -} - -guint32 -_nm_utils_ip4_get_default_prefix(in_addr_t ip) -{ - return _nm_utils_ip4_get_default_prefix0(ip) ?: 24; -} - -gboolean -nm_utils_ip_is_site_local(int addr_family, const void *address) -{ - in_addr_t addr4; - - switch (addr_family) { - case AF_INET: - /* RFC1918 private addresses - * 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 */ - addr4 = ntohl(*((const in_addr_t *) address)); - return (addr4 & 0xff000000) == 0x0a000000 || (addr4 & 0xfff00000) == 0xac100000 - || (addr4 & 0xffff0000) == 0xc0a80000; - case AF_INET6: - /* IN6_IS_ADDR_SITELOCAL() is for deprecated fec0::/10 addresses (see rfc3879, 4.). - * Note that for unique local IPv6 addresses (ULA, fc00::/7) this returns false, - * which may or may not be a bug. */ - return IN6_IS_ADDR_SITELOCAL(address); - default: - g_return_val_if_reached(FALSE); - } -} - -gboolean -nm_utils_ip6_is_ula(const struct in6_addr *address) -{ - /* Unique local IPv6 address (ULA) fc00::/7 */ - return (address->s6_addr32[0] & htonl(0xfe000000u)) == htonl(0xfc000000u); -} - -/*****************************************************************************/ - -static gboolean -_parse_legacy_addr4(const char *text, in_addr_t *out_addr, GError **error) -{ - gs_free char *s_free = NULL; - struct in_addr a1; - guint8 bin[sizeof(a1)]; - char *s; - int i; - - if (inet_aton(text, &a1) != 1) { - g_set_error_literal(error, - NM_UTILS_ERROR, - NM_UTILS_ERROR_INVALID_ARGUMENT, - "address invalid according to inet_aton()"); - return FALSE; - } - - /* OK, inet_aton() accepted the format. That's good, because we want - * to accept IPv4 addresses in octal format, like 255.255.000.000. - * That's what "legacy" means here. inet_pton() doesn't accept those. - * - * But inet_aton() also ignores trailing garbage and formats with fewer than - * 4 digits. That is just too crazy and we don't do that. Perform additional checks - * and reject some forms that inet_aton() accepted. - * - * Note that we still should (of course) accept everything that inet_pton() - * accepts. However this code never gets called if inet_pton() succeeds - * (see below, aside the assertion code). */ - - if (NM_STRCHAR_ANY(text, ch, (!(ch >= '0' && ch <= '9') && !NM_IN_SET(ch, '.', 'x')))) { - /* We only accepts '.', digits, and 'x' for "0x". */ - g_set_error_literal(error, - NM_UTILS_ERROR, - NM_UTILS_ERROR_INVALID_ARGUMENT, - "contains an invalid character"); - return FALSE; - } - - s = nm_memdup_maybe_a(300, text, strlen(text) + 1, &s_free); - - for (i = 0; i < G_N_ELEMENTS(bin); i++) { - char *current_token = s; - gint32 v; - - s = strchr(s, '.'); - if (s) { - s[0] = '\0'; - s++; - } - - if ((i == G_N_ELEMENTS(bin) - 1) != (s == NULL)) { - /* Exactly for the last digit, we expect to have no more following token. - * But this isn't the case. Abort. */ - g_set_error(error, - NM_UTILS_ERROR, - NM_UTILS_ERROR_INVALID_ARGUMENT, - "wrong number of tokens (index %d, token '%s')", - i, - s); - return FALSE; - } - - v = _nm_utils_ascii_str_to_int64(current_token, 0, 0, 0xFF, -1); - if (v == -1) { - int errsv = errno; - - /* we do accept octal and hex (even with leading "0x"). But something - * about this token is wrong. */ - g_set_error(error, - NM_UTILS_ERROR, - NM_UTILS_ERROR_INVALID_ARGUMENT, - "invalid token '%s': %s (%d)", - current_token, - nm_strerror_native(errsv), - errsv); - return FALSE; - } - - bin[i] = v; - } - - if (memcmp(bin, &a1, sizeof(bin)) != 0) { - /* our parsing did not agree with what inet_aton() gave. Something - * is wrong. Abort. */ - g_set_error( - error, - NM_UTILS_ERROR, - NM_UTILS_ERROR_INVALID_ARGUMENT, - "inet_aton() result 0x%08x differs from computed value 0x%02hhx%02hhx%02hhx%02hhx", - a1.s_addr, - bin[0], - bin[1], - bin[2], - bin[3]); - return FALSE; - } - - *out_addr = a1.s_addr; - return TRUE; -} - -gboolean -nm_utils_parse_inaddr_bin_full(int addr_family, - gboolean accept_legacy, - const char *text, - int *out_addr_family, - gpointer out_addr) -{ - NMIPAddr addrbin; - - g_return_val_if_fail(text, FALSE); - - if (addr_family == AF_UNSPEC) { - g_return_val_if_fail(!out_addr || out_addr_family, FALSE); - addr_family = strchr(text, ':') ? AF_INET6 : AF_INET; - } else - g_return_val_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6), FALSE); - - if (inet_pton(addr_family, text, &addrbin) != 1) { - if (accept_legacy && addr_family == AF_INET - && _parse_legacy_addr4(text, &addrbin.addr4, NULL)) { - /* The address is in some legacy format which inet_aton() accepts, but not inet_pton(). - * Most likely octal digits (leading zeros). We accept the address. */ - } else - return FALSE; - } - -#if NM_MORE_ASSERTS > 10 - if (addr_family == AF_INET) { - NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER - gs_free_error GError *error = NULL; - in_addr_t a; - - /* The legacy parser should accept everything that inet_pton() accepts too. Meaning, - * it should strictly parse *more* formats. And of course, parse it the same way. */ - if (!_parse_legacy_addr4(text, &a, &error)) { - char buf[INET_ADDRSTRLEN]; - - g_error("unexpected assertion failure: could parse \"%s\" as %s, but not accepted by " - "legacy parser: %s", - text, - _nm_utils_inet4_ntop(addrbin.addr4, buf), - error->message); - } - nm_assert(addrbin.addr4 == a); - NM_PRAGMA_WARNING_REENABLE - } -#endif - - NM_SET_OUT(out_addr_family, addr_family); - if (out_addr) - nm_ip_addr_set(addr_family, out_addr, &addrbin); - return TRUE; -} - -gboolean -nm_utils_parse_inaddr(int addr_family, const char *text, char **out_addr) -{ - NMIPAddr addrbin; - char addrstr_buf[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)]; - - g_return_val_if_fail(text, FALSE); - - if (addr_family == AF_UNSPEC) - addr_family = strchr(text, ':') ? AF_INET6 : AF_INET; - else - g_return_val_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6), FALSE); - - if (inet_pton(addr_family, text, &addrbin) != 1) - return FALSE; - - NM_SET_OUT(out_addr, - g_strdup(inet_ntop(addr_family, &addrbin, addrstr_buf, sizeof(addrstr_buf)))); - return TRUE; -} - -gboolean -nm_utils_parse_inaddr_prefix_bin(int addr_family, - const char *text, - int *out_addr_family, - gpointer out_addr, - int *out_prefix) -{ - gs_free char *addrstr_free = NULL; - int prefix = -1; - const char *slash; - const char *addrstr; - NMIPAddr addrbin; - - g_return_val_if_fail(text, FALSE); - - if (addr_family == AF_UNSPEC) { - g_return_val_if_fail(!out_addr || out_addr_family, FALSE); - addr_family = strchr(text, ':') ? AF_INET6 : AF_INET; - } else - g_return_val_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6), FALSE); - - slash = strchr(text, '/'); - if (slash) - addrstr = nm_strndup_a(300, text, slash - text, &addrstr_free); - else - addrstr = text; - - if (inet_pton(addr_family, addrstr, &addrbin) != 1) - return FALSE; - - if (slash) { - /* For IPv4, `ip addr add` supports the prefix-length as a netmask. We don't - * do that. */ - prefix = - _nm_utils_ascii_str_to_int64(&slash[1], 10, 0, addr_family == AF_INET ? 32 : 128, -1); - if (prefix == -1) - return FALSE; - } - - NM_SET_OUT(out_addr_family, addr_family); - if (out_addr) - nm_ip_addr_set(addr_family, out_addr, &addrbin); - NM_SET_OUT(out_prefix, prefix); - return TRUE; -} - -gboolean -nm_utils_parse_inaddr_prefix(int addr_family, const char *text, char **out_addr, int *out_prefix) -{ - NMIPAddr addrbin; - char addrstr_buf[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)]; - - if (!nm_utils_parse_inaddr_prefix_bin(addr_family, text, &addr_family, &addrbin, out_prefix)) - return FALSE; - NM_SET_OUT(out_addr, - g_strdup(inet_ntop(addr_family, &addrbin, addrstr_buf, sizeof(addrstr_buf)))); - return TRUE; -} - gboolean nm_utils_parse_next_line(const char **inout_ptr, gsize *inout_len, @@ -1323,43 +931,6 @@ done: /*****************************************************************************/ -gboolean -nm_utils_ipaddr_is_valid(int addr_family, const char *str_addr) -{ - nm_assert(NM_IN_SET(addr_family, AF_UNSPEC, AF_INET, AF_INET6)); - - return str_addr && nm_utils_parse_inaddr_bin(addr_family, str_addr, NULL, NULL); -} - -gboolean -nm_utils_ipaddr_is_normalized(int addr_family, const char *str_addr) -{ - NMIPAddr addr; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; - - nm_assert(NM_IN_SET(addr_family, AF_UNSPEC, AF_INET, AF_INET6)); - - if (!str_addr) - return FALSE; - - if (!nm_utils_parse_inaddr_bin(addr_family, str_addr, &addr_family, &addr)) - return FALSE; - - nm_utils_inet_ntop(addr_family, &addr, sbuf); - return nm_streq(sbuf, str_addr); -} - -/*****************************************************************************/ - -NM_UTILS_ENUM2STR_DEFINE(nm_icmpv6_router_pref_to_string, - NMIcmpv6RouterPref, - NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_LOW, "low"), - NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_MEDIUM, "medium"), - NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_HIGH, "high"), - NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_INVALID, "invalid"), ); - -/*****************************************************************************/ - /** * nm_g_ascii_strtoll() * @nptr: the string to parse @@ -6359,98 +5930,6 @@ _nm_utils_ssid_to_string_gbytes(GBytes *ssid) /*****************************************************************************/ -gconstpointer -nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint32 plen) -{ - g_return_val_if_fail(dst, NULL); - - switch (family) { - case AF_INET: - g_return_val_if_fail(plen <= 32, NULL); - - if (!src) { - /* allow "self-assignment", by specifying %NULL as source. */ - src = dst; - } - - *((guint32 *) dst) = nm_utils_ip4_address_clear_host_address(*((guint32 *) src), plen); - break; - case AF_INET6: - nm_utils_ip6_address_clear_host_address(dst, src, plen); - break; - default: - g_return_val_if_reached(NULL); - } - return dst; -} - -/* nm_utils_ip6_address_clear_host_address: - * @dst: destination output buffer, will contain the network part of the @src address - * @src: source ip6 address. If NULL, this does an in-place update of @dst. - * Also, @src and @dst are allowed to be the same pointers. - * @plen: prefix length of network - * - * Note: this function is self assignment safe, to update @src inplace, set both - * @dst and @src to the same destination or set @src NULL. - */ -const struct in6_addr * -nm_utils_ip6_address_clear_host_address(struct in6_addr *dst, - const struct in6_addr *src, - guint32 plen) -{ - g_return_val_if_fail(plen <= 128, NULL); - g_return_val_if_fail(dst, NULL); - - if (!src) - src = dst; - - if (plen < 128) { - guint nbytes = plen / 8; - guint nbits = plen % 8; - - if (nbytes && dst != src) - memcpy(dst, src, nbytes); - if (nbits) { - dst->s6_addr[nbytes] = (src->s6_addr[nbytes] & (0xFF << (8 - nbits))); - nbytes++; - } - if (nbytes <= 15) - memset(&dst->s6_addr[nbytes], 0, 16 - nbytes); - } else if (src != dst) - *dst = *src; - - return dst; -} - -int -nm_utils_ip6_address_same_prefix_cmp(const struct in6_addr *addr_a, - const struct in6_addr *addr_b, - guint32 plen) -{ - int nbytes; - guint8 va, vb, m; - - if (plen >= 128) { - nm_assert(plen == 128); - NM_CMP_DIRECT_MEMCMP(addr_a, addr_b, sizeof(struct in6_addr)); - } else { - nbytes = plen / 8; - if (nbytes) - NM_CMP_DIRECT_MEMCMP(addr_a, addr_b, nbytes); - - plen = plen % 8; - if (plen != 0) { - m = ~((1 << (8 - plen)) - 1); - va = ((((const guint8 *) addr_a))[nbytes]) & m; - vb = ((((const guint8 *) addr_b))[nbytes]) & m; - NM_CMP_DIRECT(va, vb); - } - } - return 0; -} - -/*****************************************************************************/ - #define IPV6_PROPERTY_DIR "/proc/sys/net/ipv6/conf/" #define IPV4_PROPERTY_DIR "/proc/sys/net/ipv4/conf/" diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index 3d8eaced07..cb3f7f9ad5 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -214,128 +214,6 @@ nm_ether_addr_equal(const NMEtherAddr *a, const NMEtherAddr *b) /*****************************************************************************/ -typedef struct { - union { - guint8 addr_ptr[sizeof(struct in6_addr)]; - in_addr_t addr4; - struct in_addr addr4_struct; - struct in6_addr addr6; - - /* NMIPAddr is really a union for IP addresses. - * However, as ethernet addresses fit in here nicely, use - * it also for an ethernet MAC address. */ - guint8 ether_addr_octet[6 /*ETH_ALEN*/]; - NMEtherAddr ether_addr; - - guint8 array[sizeof(struct in6_addr)]; - }; -} NMIPAddr; - -#define NM_IP_ADDR_INIT \ - { \ - .array = { 0 } \ - } - -extern const NMIPAddr nm_ip_addr_zero; - -#define nm_ether_addr_zero (nm_ip_addr_zero.ether_addr) - -static inline int -nm_ip_addr_cmp(int addr_family, gconstpointer a, gconstpointer b) -{ - /* Note that @a and @b are not required to be full NMIPAddr unions. - * Depending on @addr_family, they can also be only in_addr_t or - * struct in6_addr. */ - NM_CMP_SELF(a, b); - NM_CMP_DIRECT_MEMCMP(a, b, nm_utils_addr_family_to_size(addr_family)); - return 0; -} - -int nm_ip_addr_cmp_for_sort(gconstpointer a, gconstpointer b, gpointer user_data); - -static inline gboolean -nm_ip_addr_equal(int addr_family, gconstpointer a, gconstpointer b) -{ - return nm_ip_addr_cmp(addr_family, a, b) == 0; -} - -static inline gboolean -nm_ip_addr_is_null(int addr_family, gconstpointer addr) -{ - nm_assert(addr); - - if (NM_IS_IPv4(addr_family)) { - in_addr_t t; - - /* also for in_addr_t type (AF_INET), we accept that the pointer might - * be unaligned. */ - memcpy(&t, addr, sizeof(t)); - return t == 0; - } - - return IN6_IS_ADDR_UNSPECIFIED((const struct in6_addr *) addr); -} - -static inline void -nm_ip_addr_set(int addr_family, gpointer dst, gconstpointer src) -{ - nm_assert(dst); - nm_assert(src); - - /* this MUST use memcpy() to support unaligned src/dst pointers. */ - memcpy(dst, src, nm_utils_addr_family_to_size(addr_family)); - - /* Note that @dst is not necessarily a NMIPAddr, it could also be just - * an in_addr_t/struct in6_addr. We thus can only set the bytes that - * we know are present based on the address family. - * - * Using this function to initialize an NMIPAddr union (for IPv4) leaves - * uninitalized bytes. Avoid that by using nm_ip_addr_init() instead. */ -} - -static inline NMIPAddr -nm_ip_addr_init(int addr_family, gconstpointer src) -{ - NMIPAddr a; - - nm_assert_addr_family(addr_family); - nm_assert(src); - - G_STATIC_ASSERT_EXPR(sizeof(NMIPAddr) == sizeof(struct in6_addr)); - - /* this MUST use memcpy() to support unaligned src/dst pointers. */ - - if (NM_IS_IPv4(addr_family)) { - memcpy(&a, src, sizeof(in_addr_t)); - - /* ensure all bytes of the union are initialized. If only to make - * valgrind happy. */ - memset(&a.array[sizeof(in_addr_t)], 0, sizeof(a) - sizeof(in_addr_t)); - } else - memcpy(&a, src, sizeof(struct in6_addr)); - - return a; -} - -gboolean nm_ip_addr_set_from_untrusted(int addr_family, - gpointer dst, - gconstpointer src, - gsize src_len, - int *out_addr_family); - -gboolean -nm_ip_addr_set_from_variant(int addr_family, gpointer dst, GVariant *variant, int *out_addr_family); - -static inline gconstpointer -nm_ip_addr_from_packed_array(int addr_family, gconstpointer ipaddr_arr, gsize idx) -{ - return NM_IS_IPv4(addr_family) - ? ((gconstpointer) & (((const struct in_addr *) ipaddr_arr)[idx])) - : ((gconstpointer) & (((const struct in6_addr *) ipaddr_arr)[idx])); -} - -/*****************************************************************************/ - struct ether_addr; static inline int @@ -396,220 +274,6 @@ gboolean nm_utils_get_ipv6_interface_identifier(NMLinkType link_type, NMUtilsIPv6IfaceId *out_iid); /*****************************************************************************/ - -static inline guint32 -_nm_utils_ip4_netmask_to_prefix(in_addr_t subnetmask) -{ - G_STATIC_ASSERT_EXPR(__SIZEOF_INT__ == 4); - G_STATIC_ASSERT_EXPR(sizeof(int) == 4); - G_STATIC_ASSERT_EXPR(sizeof(guint) == 4); - G_STATIC_ASSERT_EXPR(sizeof(subnetmask) == 4); - - return ((subnetmask != 0u) ? (guint32) (32 - __builtin_ctz(ntohl(subnetmask))) : 0u); -} - -/** - * _nm_utils_ip4_prefix_to_netmask: - * @prefix: a CIDR prefix - * - * Returns: the netmask represented by the prefix, in network byte order - **/ -static inline in_addr_t -_nm_utils_ip4_prefix_to_netmask(guint32 prefix) -{ - nm_assert(prefix <= 32); - return prefix < 32 ? ~htonl(0xFFFFFFFFu >> prefix) : 0xFFFFFFFFu; -} - -guint32 _nm_utils_ip4_get_default_prefix0(in_addr_t ip); -guint32 _nm_utils_ip4_get_default_prefix(in_addr_t ip); - -gconstpointer -nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint32 plen); - -/* nm_utils_ip4_address_clear_host_address: - * @addr: source ip6 address - * @plen: prefix length of network - * - * returns: the input address, with the host address set to 0. - */ -static inline in_addr_t -nm_utils_ip4_address_clear_host_address(in_addr_t addr, guint32 plen) -{ - return addr & _nm_utils_ip4_prefix_to_netmask(plen); -} - -const struct in6_addr *nm_utils_ip6_address_clear_host_address(struct in6_addr *dst, - const struct in6_addr *src, - guint32 plen); - -static inline int -nm_utils_ip4_address_same_prefix_cmp(in_addr_t addr_a, in_addr_t addr_b, guint32 plen) -{ - NM_CMP_DIRECT(htonl(nm_utils_ip4_address_clear_host_address(addr_a, plen)), - htonl(nm_utils_ip4_address_clear_host_address(addr_b, plen))); - return 0; -} - -int nm_utils_ip6_address_same_prefix_cmp(const struct in6_addr *addr_a, - const struct in6_addr *addr_b, - guint32 plen); - -static inline gboolean -nm_utils_ip4_address_same_prefix(in_addr_t addr_a, in_addr_t addr_b, guint32 plen) -{ - return nm_utils_ip4_address_same_prefix_cmp(addr_a, addr_b, plen) == 0; -} - -static inline gboolean -nm_utils_ip6_address_same_prefix(const struct in6_addr *addr_a, - const struct in6_addr *addr_b, - guint8 plen) -{ - return nm_utils_ip6_address_same_prefix_cmp(addr_a, addr_b, plen) == 0; -} - -static inline int -nm_utils_ip_address_same_prefix_cmp(int addr_family, - gconstpointer addr_a, - gconstpointer addr_b, - guint8 plen) -{ - NM_CMP_SELF(addr_a, addr_b); - - if (NM_IS_IPv4(addr_family)) { - return nm_utils_ip4_address_same_prefix_cmp(*((const in_addr_t *) addr_a), - *((const in_addr_t *) addr_b), - plen); - } - - return nm_utils_ip6_address_same_prefix_cmp(addr_a, addr_b, plen); -} - -static inline gboolean -nm_utils_ip_address_same_prefix(int addr_family, - gconstpointer addr_a, - gconstpointer addr_b, - guint8 plen) -{ - return nm_utils_ip_address_same_prefix_cmp(addr_family, addr_a, addr_b, plen) == 0; -} - -#define NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX(a, b, plen) \ - NM_CMP_RETURN(nm_utils_ip4_address_same_prefix_cmp((a), (b), (plen))) - -#define NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX(a, b, plen) \ - NM_CMP_RETURN(nm_utils_ip6_address_same_prefix_cmp((a), (b), (plen))) - -/*****************************************************************************/ - -gboolean nm_utils_ip_is_site_local(int addr_family, const void *address); -gboolean nm_utils_ip6_is_ula(const struct in6_addr *address); - -/*****************************************************************************/ - -#define NM_IPV4LL_NETWORK ((in_addr_t) htonl(0xA9FE0000lu)) -#define NM_IPV4LL_NETMASK ((in_addr_t) htonl(0xFFFF0000lu)) - -static inline gboolean -nm_utils_ip4_address_is_loopback(in_addr_t addr) -{ - /* There is also IN_LOOPBACK() in , but there the - * argument is in host order not `in_addr_t`. */ - return (addr & htonl(0xFF000000u)) == htonl(0x7F000000u); -} - -static inline gboolean -nm_utils_ip4_address_is_link_local(in_addr_t addr) -{ - return (addr & NM_IPV4LL_NETMASK) == NM_IPV4LL_NETWORK; -} - -static inline gboolean -nm_utils_ip4_address_is_zeronet(in_addr_t network) -{ - /* Same as ipv4_is_zeronet() from kernel's include/linux/in.h. */ - return (network & htonl(0xFF000000u)) == htonl(0x00000000u); -} - -/*****************************************************************************/ - -#define NM_UTILS_INET_ADDRSTRLEN INET6_ADDRSTRLEN - -/* Forward declare function so we don't have to drag in . */ -const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); - -static inline const char * -nm_utils_inet_ntop(int addr_family, gconstpointer addr, char *dst) -{ - const char *s; - - nm_assert_addr_family(addr_family); - nm_assert(addr); - nm_assert(dst); - - s = inet_ntop(addr_family, - addr, - dst, - addr_family == AF_INET6 ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN); - nm_assert(s); - return s; -} - -static inline const char * -_nm_utils_inet4_ntop(in_addr_t addr, char dst[static INET_ADDRSTRLEN]) -{ - return nm_utils_inet_ntop(AF_INET, &addr, dst); -} - -static inline const char * -_nm_utils_inet6_ntop(const struct in6_addr *addr, char dst[static INET6_ADDRSTRLEN]) -{ - return nm_utils_inet_ntop(AF_INET6, addr, dst); -} - -static inline char * -nm_utils_inet_ntop_dup(int addr_family, gconstpointer addr) -{ - char buf[NM_UTILS_INET_ADDRSTRLEN]; - - return g_strdup(nm_utils_inet_ntop(addr_family, addr, buf)); -} - -static inline char * -nm_utils_inet4_ntop_dup(in_addr_t addr) -{ - return nm_utils_inet_ntop_dup(AF_INET, &addr); -} - -static inline char * -nm_utils_inet6_ntop_dup(const struct in6_addr *addr) -{ - return nm_utils_inet_ntop_dup(AF_INET6, addr); -} - -/*****************************************************************************/ - -gboolean nm_utils_ipaddr_is_valid(int addr_family, const char *str_addr); - -gboolean nm_utils_ipaddr_is_normalized(int addr_family, const char *str_addr); - -/*****************************************************************************/ - -/* this enum is compatible with ICMPV6_ROUTER_PREF_* (from , - * the values for netlink attribute RTA_PREF) and "enum ndp_route_preference" - * from . */ -typedef enum _nm_packed { - NM_ICMPV6_ROUTER_PREF_MEDIUM = 0x0, /* ICMPV6_ROUTER_PREF_MEDIUM */ - NM_ICMPV6_ROUTER_PREF_LOW = 0x3, /* ICMPV6_ROUTER_PREF_LOW */ - NM_ICMPV6_ROUTER_PREF_HIGH = 0x1, /* ICMPV6_ROUTER_PREF_HIGH */ - NM_ICMPV6_ROUTER_PREF_INVALID = 0x2, /* ICMPV6_ROUTER_PREF_INVALID */ -} NMIcmpv6RouterPref; - -const char *nm_icmpv6_router_pref_to_string(NMIcmpv6RouterPref pref, char *buf, gsize len); - -/*****************************************************************************/ - gboolean nm_utils_memeqzero(gconstpointer data, gsize length); /*****************************************************************************/ @@ -1042,31 +706,6 @@ nm_utils_escaped_tokens_options_escape_val(const char *val, char **out_to_free) /*****************************************************************************/ -gboolean nm_utils_parse_inaddr_bin_full(int addr_family, - gboolean accept_legacy, - const char *text, - int *out_addr_family, - gpointer out_addr); -static inline gboolean -nm_utils_parse_inaddr_bin(int addr_family, - const char *text, - int *out_addr_family, - gpointer out_addr) -{ - return nm_utils_parse_inaddr_bin_full(addr_family, FALSE, text, out_addr_family, out_addr); -} - -gboolean nm_utils_parse_inaddr(int addr_family, const char *text, char **out_addr); - -gboolean nm_utils_parse_inaddr_prefix_bin(int addr_family, - const char *text, - int *out_addr_family, - gpointer out_addr, - int *out_prefix); - -gboolean -nm_utils_parse_inaddr_prefix(int addr_family, const char *text, char **out_addr, int *out_prefix); - gboolean nm_utils_parse_next_line(const char **inout_ptr, gsize *inout_len, const char **out_line, @@ -1658,6 +1297,10 @@ nm_g_variant_new_au(const guint32 *data, gsize len) return g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, data, len, sizeof(guint32)); } +struct _NMIPAddr; + +extern const struct _NMIPAddr nm_ip_addr_zero; + static inline GVariant * nm_g_variant_new_ay_inaddr(int addr_family, gconstpointer addr) { -- cgit v1.2.1 From 08eff4c46ee618fcf00ddde28a425d10ba0df041 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 19 Aug 2022 13:15:20 +0200 Subject: glib-aux: rename IP address related helpers from "nm-inet-utils.h" - name things related to `in_addr_t`, `struct in6_addr`, `NMIPAddr` as `nm_ip4_addr_*()`, `nm_ip6_addr_*()`, `nm_ip_addr_*()`, respectively. - we have a wrapper `nm_inet_ntop()` for `inet_ntop()`. This name of our wrapper is chosen to be familiar with the libc underlying function. With this, also name functions that are about string representations of addresses `nm_inet_*()`, `nm_inet4_*()`, `nm_inet6_*()`. For example, `nm_inet_parse_str()`, `nm_inet_is_normalized()`. <<<< R() { git grep -l "$1" | xargs sed -i "s/\<$1\>/$2/g" } R NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX R NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX R NM_UTILS_INET_ADDRSTRLEN NM_INET_ADDRSTRLEN R _nm_utils_inet4_ntop nm_inet4_ntop R _nm_utils_inet6_ntop nm_inet6_ntop R _nm_utils_ip4_get_default_prefix nm_ip4_addr_get_default_prefix R _nm_utils_ip4_get_default_prefix0 nm_ip4_addr_get_default_prefix0 R _nm_utils_ip4_netmask_to_prefix nm_ip4_addr_netmask_to_prefix R _nm_utils_ip4_prefix_to_netmask nm_ip4_addr_netmask_from_prefix R nm_utils_inet4_ntop_dup nm_inet4_ntop_dup R nm_utils_inet6_ntop_dup nm_inet6_ntop_dup R nm_utils_inet_ntop nm_inet_ntop R nm_utils_inet_ntop_dup nm_inet_ntop_dup R nm_utils_ip4_address_clear_host_address nm_ip4_addr_clear_host_address R nm_utils_ip4_address_is_link_local nm_ip4_addr_is_link_local R nm_utils_ip4_address_is_loopback nm_ip4_addr_is_loopback R nm_utils_ip4_address_is_zeronet nm_ip4_addr_is_zeronet R nm_utils_ip4_address_same_prefix nm_ip4_addr_same_prefix R nm_utils_ip4_address_same_prefix_cmp nm_ip4_addr_same_prefix_cmp R nm_utils_ip6_address_clear_host_address nm_ip6_addr_clear_host_address R nm_utils_ip6_address_same_prefix nm_ip6_addr_same_prefix R nm_utils_ip6_address_same_prefix_cmp nm_ip6_addr_same_prefix_cmp R nm_utils_ip6_is_ula nm_ip6_addr_is_ula R nm_utils_ip_address_same_prefix nm_ip_addr_same_prefix R nm_utils_ip_address_same_prefix_cmp nm_ip_addr_same_prefix_cmp R nm_utils_ip_is_site_local nm_ip_addr_is_site_local R nm_utils_ipaddr_is_normalized nm_inet_is_normalized R nm_utils_ipaddr_is_valid nm_inet_is_valid R nm_utils_ipx_address_clear_host_address nm_ip_addr_clear_host_address R nm_utils_parse_inaddr nm_inet_parse_str R nm_utils_parse_inaddr_bin nm_inet_parse_bin R nm_utils_parse_inaddr_bin_full nm_inet_parse_bin_full R nm_utils_parse_inaddr_prefix nm_inet_parse_with_prefix_str R nm_utils_parse_inaddr_prefix_bin nm_inet_parse_with_prefix_bin R test_nm_utils_ip6_address_same_prefix test_nm_ip_addr_same_prefix ./contrib/scripts/nm-code-format.sh -F --- src/core/NetworkManagerUtils.c | 60 +++--- src/core/devices/nm-device-bond.c | 6 +- src/core/devices/nm-device-ip-tunnel.c | 10 +- src/core/devices/nm-device-utils.c | 42 ++-- src/core/devices/nm-device-vxlan.c | 28 +-- src/core/devices/nm-device-wireguard.c | 17 +- src/core/devices/nm-device.c | 12 +- src/core/devices/nm-lldp-listener.c | 2 +- src/core/devices/wifi/nm-wifi-utils.c | 6 +- src/core/devices/wwan/nm-modem-broadband.c | 7 +- src/core/devices/wwan/nm-modem-ofono.c | 13 +- src/core/dhcp/nm-dhcp-client.c | 28 +-- src/core/dhcp/nm-dhcp-nettools.c | 56 +++--- src/core/dhcp/nm-dhcp-options.c | 4 +- src/core/dhcp/nm-dhcp-systemd.c | 8 +- src/core/dhcp/nm-dhcp-utils.c | 24 +-- src/core/dns/nm-dns-dnsmasq.c | 10 +- src/core/dns/nm-dns-manager.c | 21 +- src/core/dns/nm-dns-systemd-resolved.c | 4 +- src/core/dnsmasq/nm-dnsmasq-manager.c | 4 +- src/core/dnsmasq/nm-dnsmasq-utils.c | 6 +- src/core/ndisc/nm-lndp-ndisc.c | 8 +- src/core/ndisc/nm-ndisc.c | 18 +- src/core/nm-config-data.c | 6 +- src/core/nm-connectivity.c | 8 +- src/core/nm-core-utils.c | 2 +- src/core/nm-core-utils.h | 2 +- src/core/nm-firewall-utils.c | 4 +- src/core/nm-ip-config.c | 10 +- src/core/nm-l3-config-data.c | 46 ++--- src/core/nm-l3-ipv4ll.c | 46 ++--- src/core/nm-l3-ipv6ll.c | 13 +- src/core/nm-l3cfg.c | 40 ++-- src/core/nm-netns.c | 16 +- src/core/nm-pacrunner-manager.c | 6 +- src/core/nm-policy.c | 14 +- src/core/platform/nm-fake-platform.c | 14 +- src/core/platform/tests/test-common.c | 95 +++++---- src/core/platform/tests/test-link.c | 2 +- src/core/platform/tests/test-route.c | 8 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 44 ++--- .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 8 +- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 2 +- .../plugins/ifupdown/nms-ifupdown-parser.c | 6 +- src/core/supplicant/nm-supplicant-interface.c | 2 +- src/core/tests/test-core.c | 27 ++- src/core/tests/test-l3cfg.c | 27 ++- src/core/vpn/nm-vpn-connection.c | 11 +- src/libnm-client-impl/nm-conn-utils.c | 15 +- src/libnm-client-impl/nm-ip-config.c | 4 +- src/libnm-core-impl/nm-connection.c | 4 +- src/libnm-core-impl/nm-keyfile.c | 4 +- src/libnm-core-impl/nm-setting-bond.c | 2 +- src/libnm-core-impl/nm-setting-ip-config.c | 94 +++++---- src/libnm-core-impl/nm-setting-ip-tunnel.c | 4 +- src/libnm-core-impl/nm-setting-ip6-config.c | 4 +- src/libnm-core-impl/nm-setting-vxlan.c | 4 +- src/libnm-core-impl/nm-setting-wireguard.c | 6 +- src/libnm-core-impl/nm-utils.c | 34 ++-- src/libnm-core-impl/tests/test-general.c | 20 +- src/libnm-core-impl/tests/test-setting.c | 2 +- src/libnm-core-public/nm-utils.h | 4 +- src/libnm-glib-aux/nm-inet-utils.c | 68 ++++--- src/libnm-glib-aux/nm-inet-utils.h | 144 +++++++------- src/libnm-glib-aux/nm-shared-utils.c | 4 +- src/libnm-glib-aux/nm-test-utils.h | 10 +- src/libnm-glib-aux/tests/test-shared-general.c | 28 +-- src/libnm-platform/nm-linux-platform.c | 2 +- src/libnm-platform/nm-platform.c | 213 ++++++++++----------- src/libnm-platform/nm-platform.h | 10 +- src/libnm-platform/nmp-object.c | 37 ++-- src/libnmc-setting/nm-meta-setting-desc.c | 8 +- src/nm-cloud-setup/main.c | 12 +- src/nm-cloud-setup/nm-cloud-setup-utils.c | 4 +- src/nm-cloud-setup/nmcs-provider-aliyun.c | 26 +-- src/nm-cloud-setup/nmcs-provider-azure.c | 6 +- src/nm-cloud-setup/nmcs-provider-ec2.c | 12 +- src/nm-initrd-generator/nm-initrd-generator.h | 4 +- src/nm-initrd-generator/nmi-cmdline-reader.c | 22 +-- src/nm-initrd-generator/nmi-dt-reader.c | 4 +- src/nm-initrd-generator/nmi-ibft-reader.c | 6 +- src/nmtui/nm-editor-bindings.c | 16 +- src/nmtui/nmt-ip-entry.c | 4 +- 83 files changed, 812 insertions(+), 882 deletions(-) diff --git a/src/core/NetworkManagerUtils.c b/src/core/NetworkManagerUtils.c index 8b0b484583..32c1fd17b6 100644 --- a/src/core/NetworkManagerUtils.c +++ b/src/core/NetworkManagerUtils.c @@ -419,8 +419,8 @@ route_compare(NMIPRoute *route1, NMIPRoute *route2, gint64 default_metric) nm_assert_not_reached(); if (!inet_pton(family, nm_ip_route_get_dest(route2), &a2)) nm_assert_not_reached(); - nm_utils_ipx_address_clear_host_address(family, &a1, NULL, plen); - nm_utils_ipx_address_clear_host_address(family, &a2, NULL, plen); + nm_ip_addr_clear_host_address(family, &a1, NULL, plen); + nm_ip_addr_clear_host_address(family, &a2, NULL, plen); NM_CMP_DIRECT_MEMCMP(&a1, &a2, nm_utils_addr_family_to_size(family)); return 0; @@ -1417,11 +1417,11 @@ nm_utils_ip_route_attribute_to_platform(int addr_family, && g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) { int prefix; - if (nm_utils_parse_inaddr_prefix_bin(addr_family, - g_variant_get_string(variant, NULL), - NULL, - &addr, - &prefix)) { + if (nm_inet_parse_with_prefix_bin(addr_family, + g_variant_get_string(variant, NULL), + NULL, + &addr, + &prefix)) { if (prefix < 0) prefix = 128; r6->src = addr.addr6; @@ -1443,7 +1443,7 @@ nm_utils_ip_addresses_to_dbus(int addr_family, const int IS_IPv4 = NM_IS_IPv4(addr_family); GVariantBuilder builder_data; GVariantBuilder builder_legacy; - char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + char addr_str[NM_INET_ADDRSTRLEN]; NMDedupMultiIter iter; const NMPObject *obj; guint i; @@ -1478,8 +1478,7 @@ nm_utils_ip_addresses_to_dbus(int addr_family, &addr_builder, "{sv}", "address", - g_variant_new_string( - nm_utils_inet_ntop(addr_family, address->ax.address_ptr, addr_str))); + g_variant_new_string(nm_inet_ntop(addr_family, address->ax.address_ptr, addr_str))); g_variant_builder_add(&addr_builder, "{sv}", @@ -1496,11 +1495,10 @@ nm_utils_ip_addresses_to_dbus(int addr_family, p = &address->a6.peer_address; } if (p) { - g_variant_builder_add( - &addr_builder, - "{sv}", - "peer", - g_variant_new_string(nm_utils_inet_ntop(addr_family, p, addr_str))); + g_variant_builder_add(&addr_builder, + "{sv}", + "peer", + g_variant_new_string(nm_inet_ntop(addr_family, p, addr_str))); } if (IS_IPv4) { @@ -1558,7 +1556,7 @@ nm_utils_ip_routes_to_dbus(int addr_family, const NMPObject *obj; GVariantBuilder builder_data; GVariantBuilder builder_legacy; - char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + char addr_str[NM_INET_ADDRSTRLEN]; nm_assert_addr_family(addr_family); @@ -1579,14 +1577,12 @@ nm_utils_ip_routes_to_dbus(int addr_family, nm_assert(r); nm_assert(r->rx.plen <= 8u * nm_utils_addr_family_to_size(addr_family)); nm_assert(!IS_IPv4 - || r->r4.network - == nm_utils_ip4_address_clear_host_address(r->r4.network, r->r4.plen)); - nm_assert( - IS_IPv4 - || (memcmp(&r->r6.network, - nm_utils_ip6_address_clear_host_address(&n, &r->r6.network, r->r6.plen), - sizeof(n)) - == 0)); + || r->r4.network == nm_ip4_addr_clear_host_address(r->r4.network, r->r4.plen)); + nm_assert(IS_IPv4 + || (memcmp(&r->r6.network, + nm_ip6_addr_clear_host_address(&n, &r->r6.network, r->r6.plen), + sizeof(n)) + == 0)); if (r->rx.type_coerced != nm_platform_route_type_coerce(RTN_UNICAST)) continue; @@ -1601,7 +1597,7 @@ nm_utils_ip_routes_to_dbus(int addr_family, &route_builder, "{sv}", "dest", - g_variant_new_string(nm_utils_inet_ntop(addr_family, r->rx.network_ptr, addr_str))); + g_variant_new_string(nm_inet_ntop(addr_family, r->rx.network_ptr, addr_str))); g_variant_builder_add(&route_builder, "{sv}", @@ -1614,7 +1610,7 @@ nm_utils_ip_routes_to_dbus(int addr_family, &route_builder, "{sv}", "next-hop", - g_variant_new_string(nm_utils_inet_ntop(addr_family, gateway, addr_str))); + g_variant_new_string(nm_inet_ntop(addr_family, gateway, addr_str))); } g_variant_builder_add(&route_builder, @@ -1679,7 +1675,7 @@ nm_utils_platform_capture_ip_setting(NMPlatform *platform, NMDedupMultiIter iter; const NMPObject *obj; const char *method = NULL; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; const NMPlatformIPXRoute *best_default_route = NULL; s_ip = @@ -1781,13 +1777,13 @@ nm_utils_platform_capture_ip_setting(NMPlatform *platform, } if (best_default_route && nm_setting_ip_config_get_num_addresses(s_ip) > 0) { - g_object_set(s_ip, - NM_SETTING_IP_CONFIG_GATEWAY, - nm_utils_inet_ntop( - addr_family, + g_object_set( + s_ip, + NM_SETTING_IP_CONFIG_GATEWAY, + nm_inet_ntop(addr_family, nm_platform_ip_route_get_gateway(addr_family, &best_default_route->rx), sbuf), - NULL); + NULL); } return NM_SETTING(g_steal_pointer(&s_ip)); diff --git a/src/core/devices/nm-device-bond.c b/src/core/devices/nm-device-bond.c index 44bb316dc4..558f8f7598 100644 --- a/src/core/devices/nm-device-bond.c +++ b/src/core/devices/nm-device-bond.c @@ -274,10 +274,10 @@ set_arp_targets(NMDevice *device, const char *cur_arp_ip_target, const char *new in_addr_t a4; s = new_strv[i]; - if (nm_utils_parse_inaddr_bin(AF_INET, s, NULL, &a4)) { + if (nm_inet_parse_bin(AF_INET, s, NULL, &a4)) { char sbuf[INET_ADDRSTRLEN]; - _nm_utils_inet4_ntop(a4, sbuf); + nm_inet4_ntop(a4, sbuf); if (!nm_streq(s, sbuf)) { if (!free_list) free_list = g_ptr_array_new_with_free_func(g_free); @@ -368,7 +368,7 @@ _bond_arp_ip_target_to_platform(const char *value, in_addr_t out[static NM_BOND_ for (i = 0; ip[i]; i++) { if (added > NM_BOND_MAX_ARP_TARGETS - 1) break; - if (!nm_utils_parse_inaddr_bin(AF_INET, ip[i], NULL, &in_a)) + if (!nm_inet_parse_bin(AF_INET, ip[i], NULL, &in_a)) nm_assert_not_reached(); /* verify() already validated the IP addresses */ out[added++] = in_a; diff --git a/src/core/devices/nm-device-ip-tunnel.c b/src/core/devices/nm-device-ip-tunnel.c index 02680dd7a5..7c411982d8 100644 --- a/src/core/devices/nm-device-ip-tunnel.c +++ b/src/core/devices/nm-device-ip-tunnel.c @@ -107,12 +107,12 @@ address_equal_pp(int addr_family, const char *a, const char *b) nm_assert_addr_family(addr_family); if (a) { - if (!nm_utils_parse_inaddr_bin(addr_family, a, NULL, &addr_a_val)) + if (!nm_inet_parse_bin(addr_family, a, NULL, &addr_a_val)) nm_assert_not_reached(); addr_a = &addr_a_val; } if (b) { - if (!nm_utils_parse_inaddr_bin(addr_family, b, NULL, &addr_b_val)) + if (!nm_inet_parse_bin(addr_family, b, NULL, &addr_b_val)) nm_assert_not_reached(); addr_b = &addr_b_val; } @@ -125,7 +125,7 @@ address_set(int addr_family, char **p_addr, const NMIPAddr *addr_new) { nm_assert_addr_family(addr_family); nm_assert(p_addr); - nm_assert(!*p_addr || nm_utils_ipaddr_is_normalized(addr_family, *p_addr)); + nm_assert(!*p_addr || nm_inet_is_normalized(addr_family, *p_addr)); if (!addr_new || nm_ip_addr_is_null(addr_family, addr_new)) { if (nm_clear_g_free(p_addr)) @@ -136,7 +136,7 @@ address_set(int addr_family, char **p_addr, const NMIPAddr *addr_new) if (*p_addr) { NMIPAddr addr_val; - if (!nm_utils_parse_inaddr_bin(addr_family, *p_addr, NULL, &addr_val)) + if (!nm_inet_parse_bin(addr_family, *p_addr, NULL, &addr_val)) nm_assert_not_reached(); if (nm_ip_addr_equal(addr_family, &addr_val, addr_new)) @@ -145,7 +145,7 @@ address_set(int addr_family, char **p_addr, const NMIPAddr *addr_new) g_free(*p_addr); } - *p_addr = nm_utils_inet_ntop_dup(addr_family, addr_new); + *p_addr = nm_inet_ntop_dup(addr_family, addr_new); return TRUE; } diff --git a/src/core/devices/nm-device-utils.c b/src/core/devices/nm-device-utils.c index 170922eba0..2bf24ae6da 100644 --- a/src/core/devices/nm-device-utils.c +++ b/src/core/devices/nm-device-utils.c @@ -171,25 +171,25 @@ typedef struct { #define _NMLOG_PREFIX_NAME "resolve-addr" #define _NMLOG_DOMAIN LOGD_CORE -#define _NMLOG2(level, info, ...) \ - G_STMT_START \ - { \ - if (nm_logging_enabled((level), (_NMLOG_DOMAIN))) { \ - ResolveAddrInfo *_info = (info); \ - char _addr_str[NM_UTILS_INET_ADDRSTRLEN]; \ - \ - _nm_log((level), \ - (_NMLOG_DOMAIN), \ - 0, \ - NULL, \ - NULL, \ - _NMLOG_PREFIX_NAME "[" NM_HASH_OBFUSCATE_PTR_FMT \ - ",%s]: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ - NM_HASH_OBFUSCATE_PTR(_info), \ - nm_utils_inet_ntop(_info->addr_family, &_info->address, _addr_str) \ - _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ - } \ - } \ +#define _NMLOG2(level, info, ...) \ + G_STMT_START \ + { \ + if (nm_logging_enabled((level), (_NMLOG_DOMAIN))) { \ + ResolveAddrInfo *_info = (info); \ + char _addr_str[NM_INET_ADDRSTRLEN]; \ + \ + _nm_log((level), \ + (_NMLOG_DOMAIN), \ + 0, \ + NULL, \ + NULL, \ + _NMLOG_PREFIX_NAME "[" NM_HASH_OBFUSCATE_PTR_FMT \ + ",%s]: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ + NM_HASH_OBFUSCATE_PTR(_info), \ + nm_inet_ntop(_info->addr_family, &_info->address, _addr_str) \ + _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ + } \ + } \ G_STMT_END static void @@ -234,9 +234,9 @@ resolve_addr_helper_cb(GObject *source, GAsyncResult *result, gpointer user_data static void resolve_addr_spawn_helper(ResolveAddrInfo *info) { - char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + char addr_str[NM_INET_ADDRSTRLEN]; - nm_utils_inet_ntop(info->addr_family, &info->address, addr_str); + nm_inet_ntop(info->addr_family, &info->address, addr_str); _LOG2D(info, "start lookup via nm-daemon-helper"); nm_utils_spawn_helper(NM_MAKE_STRV("resolve-address", addr_str), g_task_get_cancellable(info->task), diff --git a/src/core/devices/nm-device-vxlan.c b/src/core/devices/nm-device-vxlan.c index bf7c94c006..d2618a2970 100644 --- a/src/core/devices/nm-device-vxlan.c +++ b/src/core/devices/nm-device-vxlan.c @@ -174,15 +174,15 @@ create_and_realize(NMDevice *device, str = nm_setting_vxlan_get_local(s_vxlan); if (str) { - if (!nm_utils_parse_inaddr_bin(AF_INET, str, NULL, &props.local) - && !nm_utils_parse_inaddr_bin(AF_INET6, str, NULL, &props.local6)) + if (!nm_inet_parse_bin(AF_INET, str, NULL, &props.local) + && !nm_inet_parse_bin(AF_INET6, str, NULL, &props.local6)) return FALSE; } str = nm_setting_vxlan_get_remote(s_vxlan); if (str) { - if (!nm_utils_parse_inaddr_bin(AF_INET, str, NULL, &props.group) - && !nm_utils_parse_inaddr_bin(AF_INET6, str, NULL, &props.group6)) + if (!nm_inet_parse_bin(AF_INET, str, NULL, &props.group) + && !nm_inet_parse_bin(AF_INET6, str, NULL, &props.group6)) return FALSE; } @@ -223,7 +223,7 @@ address_matches(const char *candidate, in_addr_t addr4, struct in6_addr *addr6) if (!candidate) return addr4 == 0u && IN6_IS_ADDR_UNSPECIFIED(addr6); - if (!nm_utils_parse_inaddr_bin(AF_UNSPEC, candidate, &addr_family, &candidate_addr)) + if (!nm_inet_parse_bin(AF_UNSPEC, candidate, &addr_family, &candidate_addr)) return FALSE; if (!nm_ip_addr_equal(addr_family, @@ -401,7 +401,7 @@ update_connection(NMDevice *device, NMConnection *connection) { NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE(device); NMSettingVxlan *s_vxlan = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_VXLAN); - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; if (priv->props.id != nm_setting_vxlan_get_id(s_vxlan)) g_object_set(G_OBJECT(s_vxlan), NM_SETTING_VXLAN_ID, priv->props.id, NULL); @@ -417,12 +417,12 @@ update_connection(NMDevice *device, NMConnection *connection) if (priv->props.group) { g_object_set(s_vxlan, NM_SETTING_VXLAN_REMOTE, - _nm_utils_inet4_ntop(priv->props.group, sbuf), + nm_inet4_ntop(priv->props.group, sbuf), NULL); } else { g_object_set(s_vxlan, NM_SETTING_VXLAN_REMOTE, - _nm_utils_inet6_ntop(&priv->props.group6, sbuf), + nm_inet6_ntop(&priv->props.group6, sbuf), NULL); } } @@ -433,12 +433,12 @@ update_connection(NMDevice *device, NMConnection *connection) if (priv->props.local) { g_object_set(s_vxlan, NM_SETTING_VXLAN_LOCAL, - _nm_utils_inet4_ntop(priv->props.local, sbuf), + nm_inet4_ntop(priv->props.local, sbuf), NULL); } else if (memcmp(&priv->props.local6, &in6addr_any, sizeof(in6addr_any))) { g_object_set(s_vxlan, NM_SETTING_VXLAN_LOCAL, - _nm_utils_inet6_ntop(&priv->props.local6, sbuf), + nm_inet6_ntop(&priv->props.local6, sbuf), NULL); } } @@ -510,15 +510,15 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) break; case PROP_GROUP: if (priv->props.group) - g_value_take_string(value, nm_utils_inet4_ntop_dup(priv->props.group)); + g_value_take_string(value, nm_inet4_ntop_dup(priv->props.group)); else if (!IN6_IS_ADDR_UNSPECIFIED(&priv->props.group6)) - g_value_take_string(value, nm_utils_inet6_ntop_dup(&priv->props.group6)); + g_value_take_string(value, nm_inet6_ntop_dup(&priv->props.group6)); break; case PROP_LOCAL: if (priv->props.local) - g_value_take_string(value, nm_utils_inet4_ntop_dup(priv->props.local)); + g_value_take_string(value, nm_inet4_ntop_dup(priv->props.local)); else if (!IN6_IS_ADDR_UNSPECIFIED(&priv->props.local6)) - g_value_take_string(value, nm_utils_inet6_ntop_dup(&priv->props.local6)); + g_value_take_string(value, nm_inet6_ntop_dup(&priv->props.local6)); break; case PROP_TOS: g_value_set_uchar(value, priv->props.tos); diff --git a/src/core/devices/nm-device-wireguard.c b/src/core/devices/nm-device-wireguard.c index 179c2a22a5..62be29f106 100644 --- a/src/core/devices/nm-device-wireguard.c +++ b/src/core/devices/nm-device-wireguard.c @@ -219,7 +219,7 @@ _auto_default_route_get_enabled(NMSettingWireGuard *s_wg, aip = nm_wireguard_peer_get_allowed_ip(peer, j, &valid); if (!valid) continue; - if (!nm_utils_parse_inaddr_prefix_bin(AF_UNSPEC, aip, &addr_family, NULL, &prefix)) + if (!nm_inet_parse_with_prefix_bin(AF_UNSPEC, aip, &addr_family, NULL, &prefix)) continue; if (prefix != 0) continue; @@ -1152,11 +1152,11 @@ _peers_get_platform_list(NMDeviceWireGuardPrivate *priv, aip = nm_wireguard_peer_get_allowed_ip(peer_data->peer, i_aip, &valid); if (!valid - || !nm_utils_parse_inaddr_prefix_bin(AF_UNSPEC, - aip, - &addr_family, - &addrbin, - &prefix)) { + || !nm_inet_parse_with_prefix_bin(AF_UNSPEC, + aip, + &addr_family, + &addrbin, + &prefix)) { /* the address is really not expected to be invalid, because then * the connection would not verify. Anyway, silently skip it. */ continue; @@ -1701,8 +1701,7 @@ _get_dev2_ip_config(NMDeviceWireGuard *self, int addr_family) aip = nm_wireguard_peer_get_allowed_ip(peer, j, &valid); - if (!valid - || !nm_utils_parse_inaddr_prefix_bin(addr_family, aip, NULL, &addrbin, &prefix)) + if (!valid || !nm_inet_parse_with_prefix_bin(addr_family, aip, NULL, &addrbin, &prefix)) continue; if (prefix < 0) @@ -1722,7 +1721,7 @@ _get_dev2_ip_config(NMDeviceWireGuard *self, int addr_family) NM_L3_CONFIG_DAT_FLAGS_IGNORE_MERGE_NO_DEFAULT_ROUTES); } - nm_utils_ipx_address_clear_host_address(addr_family, &addrbin, NULL, prefix); + nm_ip_addr_clear_host_address(addr_family, &addrbin, NULL, prefix); rtable_coerced = route_table_coerced; diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index c51da9ac82..0635d14431 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -8561,7 +8561,7 @@ nm_device_generate_connection(NMDevice *self, pllink = nm_platform_link_get(nm_device_get_platform(self), priv->ifindex); if (pllink && pllink->inet6_token.id) { - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; g_object_set(s_ip6, NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, @@ -10819,7 +10819,7 @@ _dev_ipll6_set_llstate(NMDevice *self, NML3IPv6LLState llstate, const struct in6 } if (changed) { - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; _LOGT_ipll(AF_INET6, "set state %s (was %s, llstate=%s, lladdr=%s)", @@ -10828,7 +10828,7 @@ _dev_ipll6_set_llstate(NMDevice *self, NML3IPv6LLState llstate, const struct in6 nm_l3_ipv6ll_state_to_string(priv->ipll_data_6.v6.llstate), nm_ip_addr_is_null(AF_INET6, &priv->ipll_data_6.v6.lladdr) ? "(none)" - : _nm_utils_inet6_ntop(&priv->ipll_data_6.v6.lladdr, sbuf)); + : nm_inet6_ntop(&priv->ipll_data_6.v6.lladdr, sbuf)); } if (changed) @@ -13847,7 +13847,7 @@ nm_device_start_ip_check(NMDevice *self) NMSettingConnection *s_con; guint timeout = 0; const char *ping_binary = NULL; - char buf[NM_UTILS_INET_ADDRSTRLEN]; + char buf[NM_INET_ADDRSTRLEN]; NMLogDomain log_domain = LOGD_IP4; /* Shouldn't be any active ping here, since IP_CHECK happens after the @@ -13878,14 +13878,14 @@ nm_device_start_ip_check(NMDevice *self) } else if (priv->ip_data_4.state == NM_DEVICE_IP_STATE_READY) { gw = nm_l3_config_data_get_best_default_route(l3cd, AF_INET); if (gw) { - _nm_utils_inet4_ntop(NMP_OBJECT_CAST_IP4_ROUTE(gw)->gateway, buf); + nm_inet4_ntop(NMP_OBJECT_CAST_IP4_ROUTE(gw)->gateway, buf); ping_binary = nm_utils_find_helper("ping", "/usr/bin/ping", NULL); log_domain = LOGD_IP4; } } else if (priv->ip_data_6.state == NM_DEVICE_IP_STATE_READY) { gw = nm_l3_config_data_get_best_default_route(l3cd, AF_INET6); if (gw) { - _nm_utils_inet6_ntop(&NMP_OBJECT_CAST_IP6_ROUTE(gw)->gateway, buf); + nm_inet6_ntop(&NMP_OBJECT_CAST_IP6_ROUTE(gw)->gateway, buf); ping_binary = nm_utils_find_helper("ping6", "/usr/bin/ping6", NULL); log_domain = LOGD_IP6; } diff --git a/src/core/devices/nm-lldp-listener.c b/src/core/devices/nm-lldp-listener.c index 137bf8fbfe..2b077633e4 100644 --- a/src/core/devices/nm-lldp-listener.c +++ b/src/core/devices/nm-lldp-listener.c @@ -360,7 +360,7 @@ format_network_address(const guint8 *data, gsize sz) } else return NULL; - return nm_utils_inet_ntop_dup(family, &a); + return nm_inet_ntop_dup(family, &a); } static const char * diff --git a/src/core/devices/wifi/nm-wifi-utils.c b/src/core/devices/wifi/nm-wifi-utils.c index 1a8204b082..185f8c3da4 100644 --- a/src/core/devices/wifi/nm-wifi-utils.c +++ b/src/core/devices/wifi/nm-wifi-utils.c @@ -1591,12 +1591,12 @@ ip4_config_to_iwd_config(GKeyFile *file, NMSettingIPConfig *s_ip, GError **error if (num) { NMIPAddress *addr = nm_setting_ip_config_get_address(s_ip, 0); guint prefix = nm_ip_address_get_prefix(addr); - in_addr_t netmask = _nm_utils_ip4_prefix_to_netmask(prefix); + in_addr_t netmask = nm_ip4_addr_netmask_from_prefix(prefix); char buf[INET_ADDRSTRLEN]; nm_ip_address_get_address_binary(addr, &ip); g_key_file_set_string(file, "IPv4", "Address", nm_ip_address_get_address(addr)); - g_key_file_set_string(file, "IPv4", "Netmask", _nm_utils_inet4_ntop(netmask, buf)); + g_key_file_set_string(file, "IPv4", "Netmask", nm_inet4_ntop(netmask, buf)); } else { inet_pton(AF_INET, "10.42.0.100", &ip); g_key_file_set_string(file, "IPv4", "Address", "10.42.0.100"); @@ -1614,7 +1614,7 @@ ip4_config_to_iwd_config(GKeyFile *file, NMSettingIPConfig *s_ip, GError **error val = (ntohl(ip.s_addr) & 0xfffffff0) + 1; if (val == ntohl(ip.s_addr)) val += 1; - g_key_file_set_string(file, "IPv4", "Gateway", _nm_utils_inet4_ntop(htonl(val), buf)); + g_key_file_set_string(file, "IPv4", "Gateway", nm_inet4_ntop(htonl(val), buf)); } return TRUE; diff --git a/src/core/devices/wwan/nm-modem-broadband.c b/src/core/devices/wwan/nm-modem-broadband.c index 997fe72729..a4078be842 100644 --- a/src/core/devices/wwan/nm-modem-broadband.c +++ b/src/core/devices/wwan/nm-modem-broadband.c @@ -993,7 +993,7 @@ stage3_ip_config_start(NMModem *modem, int addr_family, NMModemIPMethod ip_metho /* Fully fail if invalid IP address retrieved */ address_string = mm_bearer_ip_config_get_address(self->_priv.ipv4_config); if (!address_string - || !nm_utils_parse_inaddr_bin(AF_INET, address_string, NULL, &address_network)) { + || !nm_inet_parse_bin(AF_INET, address_string, NULL, &address_network)) { g_set_error(&error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, @@ -1005,7 +1005,7 @@ stage3_ip_config_start(NMModem *modem, int addr_family, NMModemIPMethod ip_metho /* Missing gateway not a hard failure */ gw_string = mm_bearer_ip_config_get_gateway(self->_priv.ipv4_config); - if (gw_string && !nm_utils_parse_inaddr_bin(AF_INET, gw_string, NULL, &gw)) { + if (gw_string && !nm_inet_parse_bin(AF_INET, gw_string, NULL, &gw)) { g_set_error(&error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, @@ -1057,8 +1057,7 @@ stage3_ip_config_start(NMModem *modem, int addr_family, NMModemIPMethod ip_metho dns = mm_bearer_ip_config_get_dns(self->_priv.ipv4_config); for (i = 0; dns && dns[i]; i++) { - if (nm_utils_parse_inaddr_bin(AF_INET, dns[i], NULL, &address_network) - && address_network > 0) { + if (nm_inet_parse_bin(AF_INET, dns[i], NULL, &address_network) && address_network > 0) { nm_l3_config_data_add_nameserver(l3cd, AF_INET, &address_network); _LOGI(" DNS %s", dns[i]); } diff --git a/src/core/devices/wwan/nm-modem-ofono.c b/src/core/devices/wwan/nm-modem-ofono.c index c003880e6c..4a5ed6613f 100644 --- a/src/core/devices/wwan/nm-modem-ofono.c +++ b/src/core/devices/wwan/nm-modem-ofono.c @@ -786,7 +786,7 @@ handle_settings(GVariant *v_dict, gpointer user_data) _LOGW("Settings 'Address' missing"); goto out; } - if (!s || !nm_utils_parse_inaddr_bin(AF_INET, s, NULL, &address_network)) { + if (!s || !nm_inet_parse_bin(AF_INET, s, NULL, &address_network)) { _LOGW("can't convert 'Address' %s to addr", s ?: ""); goto out; } @@ -801,11 +801,11 @@ handle_settings(GVariant *v_dict, gpointer user_data) _LOGW("Settings 'Netmask' missing"); goto out; } - if (!s || !nm_utils_parse_inaddr_bin(AF_INET, s, NULL, &address_network)) { + if (!s || !nm_inet_parse_bin(AF_INET, s, NULL, &address_network)) { _LOGW("invalid 'Netmask': %s", s ?: ""); goto out; } - address.plen = _nm_utils_ip4_netmask_to_prefix(address_network); + address.plen = nm_ip4_addr_netmask_to_prefix(address_network); _LOGI("Address: %s", nm_platform_ip4_address_to_string(&address, sbuf, sizeof(sbuf))); nm_l3_config_data_add_address_4(priv->l3cd_4, &address); @@ -814,7 +814,7 @@ handle_settings(GVariant *v_dict, gpointer user_data) _LOGW("Settings 'Gateway' missing"); goto out; } - if (!nm_utils_parse_inaddr_bin(AF_INET, s, NULL, &gateway_network)) { + if (!nm_inet_parse_bin(AF_INET, s, NULL, &gateway_network)) { _LOGW("invalid 'Gateway': %s", s); goto out; } @@ -840,8 +840,7 @@ handle_settings(GVariant *v_dict, gpointer user_data) gboolean any_good = FALSE; for (; array[0]; array++) { - if (!nm_utils_parse_inaddr_bin(AF_INET, *array, NULL, &address_network) - || !address_network) { + if (!nm_inet_parse_bin(AF_INET, *array, NULL, &address_network) || !address_network) { _LOGW("invalid NameServer: %s", *array); continue; } @@ -857,7 +856,7 @@ handle_settings(GVariant *v_dict, gpointer user_data) if (g_variant_lookup(v_dict, "MessageProxy", "&s", &s)) { _LOGI("MessageProxy: %s", s); - if (s && nm_utils_parse_inaddr_bin(AF_INET, s, NULL, &address_network)) { + if (s && nm_inet_parse_bin(AF_INET, s, NULL, &address_network)) { const NMPlatformIP4Route mms_route = { .network = address_network, .plen = 32, diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c index 77cfeecf81..34873ac2e3 100644 --- a/src/core/dhcp/nm-dhcp-client.c +++ b/src/core/dhcp/nm-dhcp-client.c @@ -469,10 +469,10 @@ _acd_reglist_data_remove(NMDhcpClient *self, guint idx, gboolean do_log) reglist_data = _acd_reglist_data_get(priv, idx); if (do_log) { - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; _LOGD("acd: drop check for address %s (l3cd " NM_HASH_OBFUSCATE_PTR_FMT ")", - _nm_utils_inet4_ntop(reglist_data->addr, sbuf_addr), + nm_inet4_ntop(reglist_data->addr, sbuf_addr), NM_HASH_OBFUSCATE_PTR(reglist_data->l3cd)); } @@ -551,7 +551,7 @@ static void _acd_check_lease(NMDhcpClient *self, NMOptionBool *out_acd_state) { NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; in_addr_t addr; gboolean addr_changed = FALSE; guint idx; @@ -590,7 +590,7 @@ _acd_check_lease(NMDhcpClient *self, NMOptionBool *out_acd_state) _LOGD("acd: %s check for address %s (timeout %u msec, l3cd " NM_HASH_OBFUSCATE_PTR_FMT ")", addr_changed ? "add" : "update", - _nm_utils_inet4_ntop(addr, sbuf_addr), + nm_inet4_ntop(addr, sbuf_addr), priv->config.v4.acd_timeout_msec, NM_HASH_OBFUSCATE_PTR(priv->l3cd_next)); @@ -677,7 +677,7 @@ gboolean _nm_dhcp_client_accept_offer(NMDhcpClient *self, gconstpointer p_yiaddr) { NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; NMIPAddr yiaddr; const NML3AcdAddrInfo *acd_info; @@ -710,7 +710,7 @@ _nm_dhcp_client_accept_offer(NMDhcpClient *self, gconstpointer p_yiaddr) return TRUE; _LOGD("offered lease rejected: address %s failed ACD check", - _nm_utils_inet4_ntop(yiaddr.addr4, sbuf_addr)); + nm_inet4_ntop(yiaddr.addr4, sbuf_addr)); return FALSE; } @@ -1078,7 +1078,7 @@ static void l3_cfg_notify_cb(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, NMDhcpClient *self) { NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; nm_assert(l3cfg == priv->config.l3cfg); @@ -1240,7 +1240,7 @@ wait_dhcp_commit_done: if (acd_state != NM_OPTION_BOOL_DEFAULT) { _LOGD("acd: acd %s for %s", acd_state ? "ready" : "conflict", - _nm_utils_inet4_ntop(priv->v4.acd.addr, sbuf_addr)); + nm_inet4_ntop(priv->v4.acd.addr, sbuf_addr)); nm_l3cfg_commit_type_clear(priv->config.l3cfg, &priv->v4.acd.l3cfg_commit_handle); priv->v4.acd.state = acd_state; priv->v4.acd.done_source = nm_g_idle_add_source(_acd_complete_on_idle_cb, self); @@ -1660,14 +1660,14 @@ nm_dhcp_client_server_id_is_rejected(NMDhcpClient *self, gconstpointer addr) in_addr_t mask; int r_prefix; - if (!nm_utils_parse_inaddr_prefix_bin(AF_INET, - priv->config.reject_servers[i], - NULL, - &r_addr, - &r_prefix)) + if (!nm_inet_parse_with_prefix_bin(AF_INET, + priv->config.reject_servers[i], + NULL, + &r_addr, + &r_prefix)) nm_assert_not_reached(); - mask = _nm_utils_ip4_prefix_to_netmask(r_prefix < 0 ? 32 : r_prefix); + mask = nm_ip4_addr_netmask_from_prefix(r_prefix < 0 ? 32 : r_prefix); if ((addr4 & mask) == (r_addr & mask)) return TRUE; } diff --git a/src/core/dhcp/nm-dhcp-nettools.c b/src/core/dhcp/nm-dhcp-nettools.c index 05b7b52e95..f4f783a395 100644 --- a/src/core/dhcp/nm-dhcp-nettools.c +++ b/src/core/dhcp/nm-dhcp-nettools.c @@ -143,12 +143,12 @@ lease_option_consume_route(const uint8_t **datap, if (!nm_dhcp_lease_data_consume_in_addr(&data, &n_data, &dest)) return FALSE; - plen = _nm_utils_ip4_get_default_prefix0(dest); + plen = nm_ip4_addr_get_default_prefix0(dest); if (plen == 0) return FALSE; } - dest = nm_utils_ip4_address_clear_host_address(dest, plen); + dest = nm_ip4_addr_clear_host_address(dest, plen); if (!nm_dhcp_lease_data_consume_in_addr(&data, &n_data, &gateway)) return FALSE; @@ -239,16 +239,16 @@ lease_parse_address(NMDhcpNettools *self /* for logging context only */, r = _client_lease_query(lease, NM_DHCP_OPTION_DHCP4_SUBNET_MASK, &l_data, &l_data_len); if (r == N_DHCP4_E_UNSET) { - char str1[NM_UTILS_INET_ADDRSTRLEN]; - char str2[NM_UTILS_INET_ADDRSTRLEN]; + char str1[NM_INET_ADDRSTRLEN]; + char str2[NM_INET_ADDRSTRLEN]; /* Some DHCP servers may not set the subnet-mask (issue#1037). * Do the same as the dhclient plugin and use a default. */ - a_plen = _nm_utils_ip4_get_default_prefix(a_address.s_addr); - a_netmask = _nm_utils_ip4_prefix_to_netmask(a_plen); + a_plen = nm_ip4_addr_get_default_prefix(a_address.s_addr); + a_netmask = nm_ip4_addr_netmask_from_prefix(a_plen); _LOGT("missing subnet mask (option 1). Guess %s based on IP address %s", - _nm_utils_inet4_ntop(a_netmask, str1), - _nm_utils_inet4_ntop(a_address.s_addr, str2)); + nm_inet4_ntop(a_netmask, str1), + nm_inet4_ntop(a_address.s_addr, str2)); } else { if (r != 0 || !nm_dhcp_lease_data_parse_in_addr(l_data, @@ -261,8 +261,8 @@ lease_parse_address(NMDhcpNettools *self /* for logging context only */, "could not get netmask from lease"); return FALSE; } - a_plen = _nm_utils_ip4_netmask_to_prefix(a_netmask); - a_netmask = _nm_utils_ip4_prefix_to_netmask(a_plen); + a_plen = nm_ip4_addr_netmask_to_prefix(a_netmask); + a_netmask = nm_ip4_addr_netmask_from_prefix(a_plen); } nm_dhcp_option_add_option_in_addr(options, @@ -335,22 +335,22 @@ lease_parse_address_list(NDhcp4ClientLease *lease, nm_str_buf_reset(sbuf); for (; l_data_len > 0; l_data_len -= 4, l_data += 4) { - char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + char addr_str[NM_INET_ADDRSTRLEN]; const in_addr_t addr = unaligned_read_ne32(l_data); nm_str_buf_append_required_delimiter(sbuf, ' '); - nm_str_buf_append(sbuf, _nm_utils_inet4_ntop(addr, addr_str)); + nm_str_buf_append(sbuf, nm_inet4_ntop(addr, addr_str)); switch (option) { case NM_DHCP_OPTION_DHCP4_DOMAIN_NAME_SERVER: - if (addr == 0 || nm_utils_ip4_address_is_loopback(addr)) { + if (addr == 0 || nm_ip4_addr_is_loopback(addr)) { /* Skip localhost addresses, like also networkd does. * See https://github.com/systemd/systemd/issues/4524. */ nm_dhcp_lease_log_invalid_option(iface, AF_INET, option, "address %s is ignored", - _nm_utils_inet4_ntop(addr, addr_str)); + nm_inet4_ntop(addr, addr_str)); continue; } nm_l3_config_data_add_nameserver(l3cd, AF_INET, &addr); @@ -378,8 +378,8 @@ lease_parse_routes(NDhcp4ClientLease *lease, GHashTable *options, NMStrBuf *sbuf) { - char dest_str[NM_UTILS_INET_ADDRSTRLEN]; - char gateway_str[NM_UTILS_INET_ADDRSTRLEN]; + char dest_str[NM_INET_ADDRSTRLEN]; + char gateway_str[NM_INET_ADDRSTRLEN]; in_addr_t dest; in_addr_t gateway; uint8_t plen; @@ -412,8 +412,8 @@ lease_parse_routes(NDhcp4ClientLease *lease, nm_str_buf_reset(sbuf); while (lease_option_consume_route(&l_data, &l_data_len, TRUE, &dest, &plen, &gateway)) { - _nm_utils_inet4_ntop(dest, dest_str); - _nm_utils_inet4_ntop(gateway, gateway_str); + nm_inet4_ntop(dest, dest_str); + nm_inet4_ntop(gateway, gateway_str); nm_str_buf_append_required_delimiter(sbuf, ' '); nm_str_buf_append_printf(sbuf, "%s/%d %s", dest_str, (int) plen, gateway_str); @@ -454,8 +454,8 @@ lease_parse_routes(NDhcp4ClientLease *lease, nm_str_buf_reset(sbuf); while (lease_option_consume_route(&l_data, &l_data_len, FALSE, &dest, &plen, &gateway)) { - _nm_utils_inet4_ntop(dest, dest_str); - _nm_utils_inet4_ntop(gateway, gateway_str); + nm_inet4_ntop(dest, dest_str); + nm_inet4_ntop(gateway, gateway_str); nm_str_buf_append_required_delimiter(sbuf, ' '); nm_str_buf_append_printf(sbuf, "%s/%d %s", dest_str, (int) plen, gateway_str); @@ -501,7 +501,7 @@ lease_parse_routes(NDhcp4ClientLease *lease, while (nm_dhcp_lease_data_consume_in_addr(&l_data, &l_data_len, &gateway)) { nm_str_buf_append_required_delimiter(sbuf, ' '); - nm_str_buf_append(sbuf, _nm_utils_inet4_ntop(gateway, gateway_str)); + nm_str_buf_append(sbuf, nm_inet4_ntop(gateway, gateway_str)); if (gateway == 0) { /* silently skip 0.0.0.0 */ @@ -868,7 +868,7 @@ lease_save(NMDhcpNettools *self, NDhcp4ClientLease *lease, const char *lease_fil { struct in_addr a_address; nm_auto_str_buf NMStrBuf sbuf = NM_STR_BUF_INIT(NM_UTILS_GET_NEXT_REALLOC_SIZE_104, FALSE); - char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + char addr_str[NM_INET_ADDRSTRLEN]; gs_free_error GError *error = NULL; nm_assert(lease); @@ -879,9 +879,7 @@ lease_save(NMDhcpNettools *self, NDhcp4ClientLease *lease, const char *lease_fil return; nm_str_buf_append(&sbuf, "# This is private data. Do not parse.\n"); - nm_str_buf_append_printf(&sbuf, - "ADDRESS=%s\n", - _nm_utils_inet4_ntop(a_address.s_addr, addr_str)); + nm_str_buf_append_printf(&sbuf, "ADDRESS=%s\n", nm_inet4_ntop(a_address.s_addr, addr_str)); if (!g_file_set_contents(lease_file, nm_str_buf_get_str_unsafe(&sbuf), sbuf.len, &error)) _LOGW("error saving lease to %s: %s", lease_file, error->message); @@ -966,7 +964,7 @@ dhcp4_event_handle(NMDhcpNettools *self, NDhcp4ClientEvent *event) if (nm_dhcp_client_server_id_is_rejected(NM_DHCP_CLIENT(self), &server_id)) { _LOGD("server-id %s is in the reject-list, ignoring", - nm_utils_inet_ntop(AF_INET, &server_id, addr_str)); + nm_inet_ntop(AF_INET, &server_id, addr_str)); return; } @@ -976,8 +974,8 @@ dhcp4_event_handle(NMDhcpNettools *self, NDhcp4ClientEvent *event) } _LOGT("selecting offered lease from %s for %s", - _nm_utils_inet4_ntop(server_id.s_addr, addr_str), - _nm_utils_inet4_ntop(yiaddr.s_addr, addr_str2)); + nm_inet4_ntop(server_id.s_addr, addr_str), + nm_inet4_ntop(yiaddr.s_addr, addr_str2)); r = n_dhcp4_client_lease_select(event->offer.lease); @@ -1336,7 +1334,7 @@ ip4_start(NMDhcpClient *client, GError **error) NULL); nm_parse_env_file(contents, "ADDRESS", &s_addr); if (s_addr) - nm_utils_parse_inaddr_bin(AF_INET, s_addr, NULL, &last_addr); + nm_inet_parse_bin(AF_INET, s_addr, NULL, &last_addr); } if (last_addr.s_addr) { diff --git a/src/core/dhcp/nm-dhcp-options.c b/src/core/dhcp/nm-dhcp-options.c index 96fef81a40..5c4a821298 100644 --- a/src/core/dhcp/nm-dhcp-options.c +++ b/src/core/dhcp/nm-dhcp-options.c @@ -438,9 +438,9 @@ nm_dhcp_option_add_option_in_addr(GHashTable *options, guint option, in_addr_t value) { - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; - nm_dhcp_option_add_option(options, addr_family, option, _nm_utils_inet4_ntop(value, sbuf)); + nm_dhcp_option_add_option(options, addr_family, option, nm_inet4_ntop(value, sbuf)); } void diff --git a/src/core/dhcp/nm-dhcp-systemd.c b/src/core/dhcp/nm-dhcp-systemd.c index 49e21d97e5..d406339a09 100644 --- a/src/core/dhcp/nm-dhcp-systemd.c +++ b/src/core/dhcp/nm-dhcp-systemd.c @@ -74,7 +74,7 @@ lease_to_ip6_config(NMDhcpSystemd *self, sd_dhcp6_lease *lease, gint32 ts, GErro gs_unref_hashtable GHashTable *options = NULL; struct in6_addr tmp_addr; const struct in6_addr *dns; - char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + char addr_str[NM_INET_ADDRSTRLEN]; char **domains; char **ntp_fqdns; const struct in6_addr *ntp_addrs; @@ -107,7 +107,7 @@ lease_to_ip6_config(NMDhcpSystemd *self, sd_dhcp6_lease *lease, gint32 ts, GErro nm_l3_config_data_add_address_6(l3cd, &address); - _nm_utils_inet6_ntop(&tmp_addr, addr_str); + nm_inet6_ntop(&tmp_addr, addr_str); g_string_append(nm_gstring_add_space_delimiter(str), addr_str); has_any_addresses = TRUE; @@ -133,7 +133,7 @@ lease_to_ip6_config(NMDhcpSystemd *self, sd_dhcp6_lease *lease, gint32 ts, GErro if (num > 0) { nm_gstring_prepare(&str); for (i = 0; i < num; i++) { - _nm_utils_inet6_ntop(&dns[i], addr_str); + nm_inet6_ntop(&dns[i], addr_str); g_string_append(nm_gstring_add_space_delimiter(str), addr_str); nm_l3_config_data_add_nameserver(l3cd, AF_INET6, &dns[i]); } @@ -170,7 +170,7 @@ lease_to_ip6_config(NMDhcpSystemd *self, sd_dhcp6_lease *lease, gint32 ts, GErro num = sd_dhcp6_lease_get_ntp_addrs(lease, &ntp_addrs); if (num > 0) { for (i = 0; i < num; i++) { - _nm_utils_inet6_ntop(&ntp_addrs[i], addr_str); + nm_inet6_ntop(&ntp_addrs[i], addr_str); g_string_append(nm_gstring_add_space_delimiter(str), addr_str); } } diff --git a/src/core/dhcp/nm-dhcp-utils.c b/src/core/dhcp/nm-dhcp-utils.c index 1bffb3c437..6a389dbef4 100644 --- a/src/core/dhcp/nm-dhcp-utils.c +++ b/src/core/dhcp/nm-dhcp-utils.c @@ -94,7 +94,7 @@ ip4_process_dhcpcd_rfc3442_routes(const char *iface, l3cd, &((const NMPlatformIP4Route){ .rt_source = NM_IP_CONFIG_SOURCE_DHCP, - .network = nm_utils_ip4_address_clear_host_address(rt_addr, rt_cidr), + .network = nm_ip4_addr_clear_host_address(rt_addr, rt_cidr), .plen = rt_cidr, .gateway = rt_route, .pref_src = address, @@ -139,7 +139,7 @@ process_dhclient_rfc3442_route(const char *const **p_octets, NMPlatformIP4Route str_addr = g_strjoin(".", addr[0], addr[1], addr[2], addr[3], NULL); if (inet_pton(AF_INET, str_addr, &tmp_addr) <= 0) return FALSE; - v_network = nm_utils_ip4_address_clear_host_address(tmp_addr, v_plen); + v_network = nm_ip4_addr_clear_host_address(tmp_addr, v_plen); } next_hop = g_strjoin(".", o[0], o[1], o[2], o[3], NULL); @@ -203,9 +203,9 @@ ip4_process_dhclient_rfc3442_routes(const char *iface, _LOG2I(LOGD_DHCP4, iface, " classless static route %s/%d gw %s", - _nm_utils_inet4_ntop(route.network, b1), + nm_inet4_ntop(route.network, b1), route.plen, - _nm_utils_inet4_ntop(route.gateway, b2)); + nm_inet4_ntop(route.gateway, b2)); } } @@ -324,8 +324,8 @@ process_classful_routes(const char *iface, * The Static Routes option (option 33) does not provide a subnet mask * for each route - it is assumed that the subnet mask is implicit in * whatever network number is specified in each route entry */ - route.plen = _nm_utils_ip4_get_default_prefix(rt_addr); - if (rt_addr & ~_nm_utils_ip4_prefix_to_netmask(route.plen)) { + route.plen = nm_ip4_addr_get_default_prefix(rt_addr); + if (rt_addr & ~nm_ip4_addr_netmask_from_prefix(route.plen)) { /* RFC 943: target not "this network"; using host routing */ route.plen = 32; } @@ -337,7 +337,7 @@ process_classful_routes(const char *iface, route.metric_any = TRUE; route.metric = 0; - route.network = nm_utils_ip4_address_clear_host_address(route.network, route.plen); + route.network = nm_ip4_addr_clear_host_address(route.network, route.plen); nm_l3_config_data_add_route_4(l3cd, &route); @@ -400,7 +400,7 @@ nm_dhcp_utils_ip4_config_from_options(NMDedupMultiIndex *multi_idx, gboolean gateway_has = FALSE; guint32 gateway = 0; guint8 plen = 0; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; guint32 now; g_return_val_if_fail(options != NULL, NULL); @@ -414,7 +414,7 @@ nm_dhcp_utils_ip4_config_from_options(NMDedupMultiIndex *multi_idx, }; str = g_hash_table_lookup(options, "ip_address"); - if (!str || !nm_utils_parse_inaddr_bin(AF_INET, str, NULL, &addr)) + if (!str || !nm_inet_parse_bin(AF_INET, str, NULL, &addr)) return NULL; if (addr == INADDR_ANY) return NULL; @@ -423,11 +423,11 @@ nm_dhcp_utils_ip4_config_from_options(NMDedupMultiIndex *multi_idx, str = g_hash_table_lookup(options, "subnet_mask"); if (str && (inet_pton(AF_INET, str, &tmp_addr) > 0)) { - plen = _nm_utils_ip4_netmask_to_prefix(tmp_addr); + plen = nm_ip4_addr_netmask_to_prefix(tmp_addr); _LOG2I(LOGD_DHCP4, iface, " plen %d (%s)", plen, str); } else { /* Get default netmask for the IP according to appropriate class. */ - plen = _nm_utils_ip4_get_default_prefix(addr); + plen = nm_ip4_addr_get_default_prefix(addr); _LOG2I(LOGD_DHCP4, iface, " plen %d (default)", plen); } @@ -440,7 +440,7 @@ nm_dhcp_utils_ip4_config_from_options(NMDedupMultiIndex *multi_idx, process_classful_routes(iface, options, l3cd, address.address); if (gateway) { - _LOG2I(LOGD_DHCP4, iface, " gateway %s", _nm_utils_inet4_ntop(gateway, sbuf)); + _LOG2I(LOGD_DHCP4, iface, " gateway %s", nm_inet4_ntop(gateway, sbuf)); gateway_has = TRUE; } else { /* If the gateway wasn't provided as a classless static route with a diff --git a/src/core/dns/nm-dns-dnsmasq.c b/src/core/dns/nm-dns-dnsmasq.c index cc7c03a21b..495208b19e 100644 --- a/src/core/dns/nm-dns-dnsmasq.c +++ b/src/core/dns/nm-dns-dnsmasq.c @@ -801,13 +801,13 @@ add_dnsmasq_nameserver(NMDnsDnsmasq *self, g_variant_builder_close(servers); } -#define IP_ADDR_TO_STRING_BUFLEN (NM_UTILS_INET_ADDRSTRLEN + 1 + IFNAMSIZ) +#define IP_ADDR_TO_STRING_BUFLEN (NM_INET_ADDRSTRLEN + 1 + IFNAMSIZ) static const char * ip_addr_to_string(int addr_family, gconstpointer addr, const char *iface, char *out_buf) { int n_written; - char buf2[NM_UTILS_INET_ADDRSTRLEN]; + char buf2[NM_INET_ADDRSTRLEN]; const char *separator; nm_assert_addr_family(addr_family); @@ -815,13 +815,13 @@ ip_addr_to_string(int addr_family, gconstpointer addr, const char *iface, char * nm_assert(out_buf); if (addr_family == AF_INET) { - nm_utils_inet_ntop(addr_family, addr, buf2); + nm_inet_ntop(addr_family, addr, buf2); separator = "@"; } else { if (IN6_IS_ADDR_V4MAPPED(addr)) - _nm_utils_inet4_ntop(((const struct in6_addr *) addr)->s6_addr32[3], buf2); + nm_inet4_ntop(((const struct in6_addr *) addr)->s6_addr32[3], buf2); else - _nm_utils_inet6_ntop(addr, buf2); + nm_inet6_ntop(addr, buf2); /* Need to scope link-local addresses with %. Before dnsmasq 2.58, * only '@' was supported as delimiter. Since 2.58, '@' and '%' are * supported. Due to a bug, since 2.73 only '%' works properly as "server" diff --git a/src/core/dns/nm-dns-manager.c b/src/core/dns/nm-dns-manager.c index 16af1d2dfe..7b44e090c6 100644 --- a/src/core/dns/nm-dns-manager.c +++ b/src/core/dns/nm-dns-manager.c @@ -552,7 +552,7 @@ add_dns_domains(GPtrArray *array, static void merge_one_l3cd(NMResolvConfData *rc, int addr_family, int ifindex, const NML3ConfigData *l3cd) { - char buf[NM_UTILS_INET_ADDRSTRLEN + 50]; + char buf[NM_INET_ADDRSTRLEN + 50]; gboolean has_trust_ad; guint num_nameservers; guint num; @@ -569,11 +569,11 @@ merge_one_l3cd(NMResolvConfData *rc, int addr_family, int ifindex, const NML3Con addr = nm_ip_addr_from_packed_array(addr_family, nameservers, i); if (addr_family == AF_INET) - nm_utils_inet_ntop(addr_family, addr, buf); + nm_inet_ntop(addr_family, addr, buf); else if (IN6_IS_ADDR_V4MAPPED(addr)) - _nm_utils_inet4_ntop(addr->addr6.s6_addr32[3], buf); + nm_inet4_ntop(addr->addr6.s6_addr32[3], buf); else { - _nm_utils_inet6_ntop(&addr->addr6, buf); + nm_inet6_ntop(&addr->addr6, buf); if (IN6_IS_ADDR_LINKLOCAL(addr)) { const char *ifname; @@ -619,7 +619,7 @@ merge_one_l3cd(NMResolvConfData *rc, int addr_family, int ifindex, const NML3Con nis_servers = nm_l3_config_data_get_nis_servers(l3cd, &num); for (i = 0; i < num; i++) - add_string_item(rc->nis_servers, _nm_utils_inet4_ntop(nis_servers[i], buf), TRUE); + add_string_item(rc->nis_servers, nm_inet4_ntop(nis_servers[i], buf), TRUE); if ((nis_domain = nm_l3_config_data_get_nis_domain(l3cd))) { /* FIXME: handle multiple domains */ @@ -1258,7 +1258,7 @@ merge_global_dns_config(NMResolvConfData *rc, NMGlobalDnsConfig *global_conf) static const char * get_nameserver_list(int addr_family, const NML3ConfigData *l3cd, NMStrBuf *tmp_strbuf) { - char buf[NM_UTILS_INET_ADDRSTRLEN]; + char buf[NM_INET_ADDRSTRLEN]; guint num; guint i; gconstpointer nameservers; @@ -1270,7 +1270,7 @@ get_nameserver_list(int addr_family, const NML3ConfigData *l3cd, NMStrBuf *tmp_s const NMIPAddr *addr; addr = nm_ip_addr_from_packed_array(addr_family, nameservers, i); - nm_utils_inet_ntop(addr_family, addr->addr_ptr, buf); + nm_inet_ntop(addr_family, addr->addr_ptr, buf); if (i > 0) nm_str_buf_append_c(tmp_strbuf, ' '); nm_str_buf_append(tmp_strbuf, buf); @@ -2083,8 +2083,7 @@ nm_dns_manager_set_hostname(NMDnsManager *self, const char *hostname, gboolean s /* Certain hostnames we don't want to include in resolv.conf 'searches' */ if (hostname && nm_utils_is_specific_hostname(hostname) - && !g_str_has_suffix(hostname, ".in-addr.arpa") - && !nm_utils_ipaddr_is_valid(AF_UNSPEC, hostname)) { + && !g_str_has_suffix(hostname, ".in-addr.arpa") && !nm_inet_is_valid(AF_UNSPEC, hostname)) { domain = strchr(hostname, '.'); if (domain) { domain++; @@ -2628,7 +2627,7 @@ _get_config_variant(NMDnsManager *self) guint num_domains; guint num_searches; guint i; - char buf[NM_UTILS_INET_ADDRSTRLEN]; + char buf[NM_INET_ADDRSTRLEN]; const char *ifname; gconstpointer nameservers; @@ -2645,7 +2644,7 @@ _get_config_variant(NMDnsManager *self) addr = nm_ip_addr_from_packed_array(ip_data->addr_family, nameservers, i); g_variant_builder_add(&strv_builder, "s", - nm_utils_inet_ntop(ip_data->addr_family, addr, buf)); + nm_inet_ntop(ip_data->addr_family, addr, buf)); } g_variant_builder_add(&entry_builder, "{sv}", diff --git a/src/core/dns/nm-dns-systemd-resolved.c b/src/core/dns/nm-dns-systemd-resolved.c index e0b94647f5..5a22fa25ca 100644 --- a/src/core/dns/nm-dns-systemd-resolved.c +++ b/src/core/dns/nm-dns-systemd-resolved.c @@ -1066,7 +1066,7 @@ nm_dns_systemd_resolved_resolve_address(NMDnsSystemdResolved { NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); NMDnsSystemdResolvedResolveHandle *handle; - char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + char addr_str[NM_INET_ADDRSTRLEN]; g_return_val_if_fail(NM_IS_DNS_SYSTEMD_RESOLVED(self), NULL); nm_assert_addr_family(addr_family); @@ -1092,7 +1092,7 @@ nm_dns_systemd_resolved_resolve_address(NMDnsSystemdResolved _LOG2T(handle, "resolve-address(ifindex=%d, %s, flags=%" G_GINT64_MODIFIER "x): new request", handle->r_address.ifindex, - nm_utils_inet_ntop(handle->r_address.addr_family, &handle->r_address.addr, addr_str), + nm_inet_ntop(handle->r_address.addr_family, &handle->r_address.addr, addr_str), handle->r_address.flags); _resolve_start(self, handle); diff --git a/src/core/dnsmasq/nm-dnsmasq-manager.c b/src/core/dnsmasq/nm-dnsmasq-manager.c index be463da3e8..2cdfb29643 100644 --- a/src/core/dnsmasq/nm-dnsmasq-manager.c +++ b/src/core/dnsmasq/nm-dnsmasq-manager.c @@ -147,7 +147,7 @@ create_dm_cmd_line(const char *iface, */ nm_strv_ptrarray_add_string_dup(cmd, "--strict-order"); - _nm_utils_inet4_ntop(listen_address->address, listen_address_s); + nm_inet4_ntop(listen_address->address, listen_address_s); nm_strv_ptrarray_add_string_concat(cmd, "--listen-address=", listen_address_s); @@ -169,7 +169,7 @@ create_dm_cmd_line(const char *iface, g_string_append(s, "--dhcp-option=option:dns-server"); for (i = 0; i < n; i++) { g_string_append_c(s, ','); - g_string_append(s, _nm_utils_inet4_ntop(ipv4arr[i], sbuf_addr)); + g_string_append(s, nm_inet4_ntop(ipv4arr[i], sbuf_addr)); } nm_strv_ptrarray_take_gstring(cmd, &s); } diff --git a/src/core/dnsmasq/nm-dnsmasq-utils.c b/src/core/dnsmasq/nm-dnsmasq-utils.c index 7f79987830..69424d74a6 100644 --- a/src/core/dnsmasq/nm-dnsmasq-utils.c +++ b/src/core/dnsmasq/nm-dnsmasq-utils.c @@ -50,7 +50,7 @@ nm_dnsmasq_utils_get_range(const NMPlatformIP4Address *addr, prefix = 24; } - netmask = _nm_utils_ip4_prefix_to_netmask(prefix); + netmask = nm_ip4_addr_netmask_from_prefix(prefix); /* treat addresses in host-order from here on. */ netmask = ntohl(netmask); @@ -96,8 +96,8 @@ nm_dnsmasq_utils_get_range(const NMPlatformIP4Address *addr, first = htonl(first); last = htonl(last); - _nm_utils_inet4_ntop(first, out_first); - _nm_utils_inet4_ntop(last, out_last); + nm_inet4_ntop(first, out_first); + nm_inet4_ntop(last, out_last); return TRUE; } diff --git a/src/core/ndisc/nm-lndp-ndisc.c b/src/core/ndisc/nm-lndp-ndisc.c index 313756a61a..38eacd2a42 100644 --- a/src/core/ndisc/nm-lndp-ndisc.c +++ b/src/core/ndisc/nm-lndp-ndisc.c @@ -202,9 +202,7 @@ receive_ra(struct ndp *ndp, struct ndp_msg *msg, gpointer user_data) r_plen = ndp_msg_opt_prefix_len(msg, offset); if (r_plen == 0 || r_plen > 128) continue; - nm_utils_ip6_address_clear_host_address(&r_network, - ndp_msg_opt_prefix(msg, offset), - r_plen); + nm_ip6_addr_clear_host_address(&r_network, ndp_msg_opt_prefix(msg, offset), r_plen); if (IN6_IS_ADDR_UNSPECIFIED(&r_network) || IN6_IS_ADDR_LINKLOCAL(&r_network)) continue; @@ -244,9 +242,7 @@ receive_ra(struct ndp *ndp, struct ndp_msg *msg, gpointer user_data) if (plen == 0 || plen > 128) continue; - nm_utils_ip6_address_clear_host_address(&network, - ndp_msg_opt_route_prefix(msg, offset), - plen); + nm_ip6_addr_clear_host_address(&network, ndp_msg_opt_route_prefix(msg, offset), plen); { const NMNDiscRoute route = { diff --git a/src/core/ndisc/nm-ndisc.c b/src/core/ndisc/nm-ndisc.c index 04b673e51d..ec5a83c622 100644 --- a/src/core/ndisc/nm-ndisc.c +++ b/src/core/ndisc/nm-ndisc.c @@ -1233,9 +1233,9 @@ nm_ndisc_dad_failed(NMNDisc *ndisc, const struct in6_addr *address, gboolean emi NMNDiscAddress *item = &g_array_index(rdata->addresses, NMNDiscAddress, i); if (IN6_ARE_ADDR_EQUAL(&item->address, address)) { - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; - _LOGD("DAD failed for discovered address %s", _nm_utils_inet6_ntop(address, sbuf)); + _LOGD("DAD failed for discovered address %s", nm_inet6_ntop(address, sbuf)); changed = TRUE; if (!complete_address(ndisc, item)) { g_array_remove_index(rdata->addresses, i); @@ -1278,7 +1278,7 @@ _config_changed_log(NMNDisc *ndisc, NMNDiscConfigMap changed) NMNDiscDataInternal *rdata; guint i; char changedstr[CONFIG_MAP_MAX_STR]; - char addrstr[NM_UTILS_INET_ADDRSTRLEN]; + char addrstr[NM_INET_ADDRSTRLEN]; char str_pref[35]; char str_exp[100]; gint64 now_msec; @@ -1306,7 +1306,7 @@ _config_changed_log(NMNDisc *ndisc, NMNDiscConfigMap changed) const NMNDiscGateway *gateway = &g_array_index(rdata->gateways, NMNDiscGateway, i); _LOGD(" gateway %s pref %s exp %s", - _nm_utils_inet6_ntop(&gateway->address, addrstr), + nm_inet6_ntop(&gateway->address, addrstr), nm_icmpv6_router_pref_to_string(gateway->preference, str_pref, sizeof(str_pref)), get_exp(str_exp, now_msec, gateway)); } @@ -1314,17 +1314,17 @@ _config_changed_log(NMNDisc *ndisc, NMNDiscConfigMap changed) const NMNDiscAddress *address = &g_array_index(rdata->addresses, NMNDiscAddress, i); _LOGD(" address %s exp %s", - _nm_utils_inet6_ntop(&address->address, addrstr), + nm_inet6_ntop(&address->address, addrstr), get_exp(str_exp, now_msec, address)); } for (i = 0; i < rdata->routes->len; i++) { const NMNDiscRoute *route = &g_array_index(rdata->routes, NMNDiscRoute, i); - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; _LOGD(" route %s/%u via %s pref %s exp %s", - _nm_utils_inet6_ntop(&route->network, addrstr), + nm_inet6_ntop(&route->network, addrstr), (guint) route->plen, - _nm_utils_inet6_ntop(&route->gateway, sbuf), + nm_inet6_ntop(&route->gateway, sbuf), nm_icmpv6_router_pref_to_string(route->preference, str_pref, sizeof(str_pref)), get_exp(str_exp, now_msec, route)); } @@ -1333,7 +1333,7 @@ _config_changed_log(NMNDisc *ndisc, NMNDiscConfigMap changed) &g_array_index(rdata->dns_servers, NMNDiscDNSServer, i); _LOGD(" dns_server %s exp %s", - _nm_utils_inet6_ntop(&dns_server->address, addrstr), + nm_inet6_ntop(&dns_server->address, addrstr), get_exp(str_exp, now_msec, dns_server)); } for (i = 0; i < rdata->dns_domains->len; i++) { diff --git a/src/core/nm-config-data.c b/src/core/nm-config-data.c index 0f512e3865..fd98797186 100644 --- a/src/core/nm-config-data.c +++ b/src/core/nm-config-data.c @@ -1168,8 +1168,7 @@ load_global_dns(GKeyFile *keyfile, gboolean internal) if (strv) { nm_strv_cleanup(strv, TRUE, TRUE, TRUE); for (i = 0, j = 0; strv[i]; i++) { - if (nm_utils_ipaddr_is_valid(AF_INET, strv[i]) - || nm_utils_ipaddr_is_valid(AF_INET6, strv[i])) + if (nm_inet_is_valid(AF_INET, strv[i]) || nm_inet_is_valid(AF_INET6, strv[i])) strv[j++] = strv[i]; else g_free(strv[i]); @@ -1305,8 +1304,7 @@ global_dns_domain_from_dbus(char *name, GVariant *variant) strv = g_variant_dup_strv(val, NULL); nm_strv_cleanup(strv, TRUE, TRUE, TRUE); for (i = 0, j = 0; strv && strv[i]; i++) { - if (nm_utils_ipaddr_is_valid(AF_INET, strv[i]) - || nm_utils_ipaddr_is_valid(AF_INET6, strv[i])) + if (nm_inet_is_valid(AF_INET, strv[i]) || nm_inet_is_valid(AF_INET6, strv[i])) strv[j++] = strv[i]; else g_free(strv[i]); diff --git a/src/core/nm-connectivity.c b/src/core/nm-connectivity.c index 25ac3c7f8c..5bfae71a29 100644 --- a/src/core/nm-connectivity.c +++ b/src/core/nm-connectivity.c @@ -805,7 +805,7 @@ system_resolver_resolve_cb(GObject *source_object, GAsyncResult *res, gpointer u for (iter = list; iter; iter = iter->next) { GInetAddress *a = iter->data; - char str_addr[NM_UTILS_INET_ADDRSTRLEN]; + char str_addr[NM_INET_ADDRSTRLEN]; int addr_family; switch (g_inet_address_get_family(a)) { @@ -830,7 +830,7 @@ system_resolver_resolve_cb(GObject *source_object, GAsyncResult *res, gpointer u nm_str_buf_append_c(&strbuf_hosts, ','); nm_str_buf_append(&strbuf_hosts, - nm_utils_inet_ntop(addr_family, g_inet_address_to_bytes(a), str_addr)); + nm_inet_ntop(addr_family, g_inet_address_to_bytes(a), str_addr)); next:; } @@ -905,7 +905,7 @@ systemd_resolved_resolve_cb(GObject *object, GAsyncResult *res, gpointer user_da for (i = 0; i < no_addresses; i++) { gs_unref_variant GVariant *address = NULL; - char str_addr[NM_UTILS_INET_ADDRSTRLEN]; + char str_addr[NM_INET_ADDRSTRLEN]; const guchar *address_buf; g_variant_get_child(addresses, i, "(ii@ay)", &ifindex, &addr_family, &address); @@ -928,7 +928,7 @@ systemd_resolved_resolve_cb(GObject *object, GAsyncResult *res, gpointer user_da } else nm_str_buf_append_c(&strbuf_hosts, ','); - nm_str_buf_append(&strbuf_hosts, nm_utils_inet_ntop(addr_family, address_buf, str_addr)); + nm_str_buf_append(&strbuf_hosts, nm_inet_ntop(addr_family, address_buf, str_addr)); } if (strbuf_hosts.len == 0) { _LOG2D("systemd-resolve returned no usable IPv%c addresses", diff --git a/src/core/nm-core-utils.c b/src/core/nm-core-utils.c index 480e9b28f0..0d325f0fe1 100644 --- a/src/core/nm-core-utils.c +++ b/src/core/nm-core-utils.c @@ -4186,7 +4186,7 @@ nm_utils_get_reverse_dns_domains_ip_6(const struct in6_addr *ip, guint8 plen, GP return; memcpy(&addr, ip, sizeof(struct in6_addr)); - nm_utils_ip6_address_clear_host_address(&addr, NULL, plen); + nm_ip6_addr_clear_host_address(&addr, NULL, plen); /* Number of nibbles to include in domains */ nibbles = (plen - 1) / 4 + 1; diff --git a/src/core/nm-core-utils.h b/src/core/nm-core-utils.h index d1a62a607f..5852bff33c 100644 --- a/src/core/nm-core-utils.h +++ b/src/core/nm-core-utils.h @@ -112,7 +112,7 @@ nm_hash_update_in6addr_prefix(NMHashState *h, const struct in6_addr *addr, guint nm_assert(addr); - nm_utils_ip6_address_clear_host_address(&a, addr, plen); + nm_ip6_addr_clear_host_address(&a, addr, plen); /* we don't hash plen itself. The caller may want to do that.*/ nm_hash_update_in6addr(h, &a); } diff --git a/src/core/nm-firewall-utils.c b/src/core/nm-firewall-utils.c index 1311f50399..54e3f429aa 100644 --- a/src/core/nm-firewall-utils.c +++ b/src/core/nm-firewall-utils.c @@ -50,12 +50,12 @@ _share_iptables_subnet_to_str(char buf[static _SHARE_IPTABLES_SUBNET_TO_STR in_addr_t netmask; int l; - netmask = _nm_utils_ip4_prefix_to_netmask(plen); + netmask = nm_ip4_addr_netmask_from_prefix(plen); l = g_snprintf(buf, _SHARE_IPTABLES_SUBNET_TO_STR_LEN, "%s/%u", - _nm_utils_inet4_ntop(addr & netmask, buf_addr), + nm_inet4_ntop(addr & netmask, buf_addr), plen); nm_assert(l < _SHARE_IPTABLES_SUBNET_TO_STR_LEN); return buf; diff --git a/src/core/nm-ip-config.c b/src/core/nm-ip-config.c index b191b54bb2..12f4fadff0 100644 --- a/src/core/nm-ip-config.c +++ b/src/core/nm-ip-config.c @@ -90,7 +90,7 @@ get_property_ip(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec NMIPConfig *self = NM_IP_CONFIG(object); NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); const int addr_family = nm_ip_config_get_addr_family(self); - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; const char *const *strv; guint len; int v_i; @@ -108,7 +108,7 @@ get_property_ip(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec NMP_OBJECT_CAST_IP_ROUTE(priv->v_gateway.best_default_route)); g_value_set_variant( value, - g_variant_new_string(nm_utils_inet_ntop(addr_family, gateway, sbuf_addr))); + g_variant_new_string(nm_inet_ntop(addr_family, gateway, sbuf_addr))); } else g_value_set_variant(value, nm_g_variant_singleton_s_empty()); break; @@ -333,7 +333,7 @@ get_property_ip4(GObject *object, guint prop_id, GValue *value, GParamSpec *pspe { NMIPConfig *self = NM_IP_CONFIG(object); NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); - char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + char addr_str[NM_INET_ADDRSTRLEN]; GVariantBuilder builder; const in_addr_t *addrs; guint len; @@ -361,7 +361,7 @@ get_property_ip4(GObject *object, guint prop_id, GValue *value, GParamSpec *pspe for (i = 0; i < len; i++) { GVariantBuilder nested_builder; - _nm_utils_inet4_ntop(addrs[i], addr_str); + nm_inet4_ntop(addrs[i], addr_str); g_variant_builder_init(&nested_builder, G_VARIANT_TYPE("a{sv}")); g_variant_builder_add(&nested_builder, @@ -387,7 +387,7 @@ get_property_ip4(GObject *object, guint prop_id, GValue *value, GParamSpec *pspe else { g_variant_builder_init(&builder, G_VARIANT_TYPE("as")); for (i = 0; i < len; i++) - g_variant_builder_add(&builder, "s", _nm_utils_inet4_ntop(addrs[i], addr_str)); + g_variant_builder_add(&builder, "s", nm_inet4_ntop(addrs[i], addr_str)); g_value_take_variant(value, g_variant_builder_end(&builder)); } break; diff --git a/src/core/nm-l3-config-data.c b/src/core/nm-l3-config-data.c index bcd0b62a84..42467d50e8 100644 --- a/src/core/nm-l3-config-data.c +++ b/src/core/nm-l3-config-data.c @@ -352,7 +352,7 @@ nm_l3_config_data_log(const NML3ConfigData *self, NMLogDomain log_domain) { char sbuf[NM_UTILS_TO_STRING_BUFFER_SIZE]; - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; int IS_IPv4; guint i; @@ -484,9 +484,9 @@ nm_l3_config_data_log(const NML3ConfigData *self, _L("nameserver%c[%u]: %s", nm_utils_addr_family_to_char(addr_family), i, - nm_utils_inet_ntop(addr_family, - _garray_inaddr_at(self->nameservers_x[IS_IPv4], IS_IPv4, i), - sbuf_addr)); + nm_inet_ntop(addr_family, + _garray_inaddr_at(self->nameservers_x[IS_IPv4], IS_IPv4, i), + sbuf_addr)); } for (i = 0; i < nm_g_ptr_array_len(self->domains_x[IS_IPv4]); i++) { @@ -514,12 +514,12 @@ nm_l3_config_data_log(const NML3ConfigData *self, for (i = 0; i < nm_g_array_len(self->wins); i++) { _L("wins[%u]: %s", i, - _nm_utils_inet4_ntop(g_array_index(self->wins, in_addr_t, i), sbuf_addr)); + nm_inet4_ntop(g_array_index(self->wins, in_addr_t, i), sbuf_addr)); } for (i = 0; i < nm_g_array_len(self->nis_servers); i++) { _L("nis-server[%u]: %s", i, - _nm_utils_inet4_ntop(g_array_index(self->nis_servers, in_addr_t, i), sbuf_addr)); + nm_inet4_ntop(g_array_index(self->nis_servers, in_addr_t, i), sbuf_addr)); } if (self->nis_domain) _L("nis-domain: %s", self->nis_domain->str); @@ -621,8 +621,7 @@ nm_l3_config_data_log(const NML3ConfigData *self, static gboolean _route_valid_4(const NMPlatformIP4Route *r) { - return r && r->plen <= 32 - && r->network == nm_utils_ip4_address_clear_host_address(r->network, r->plen); + return r && r->plen <= 32 && r->network == nm_ip4_addr_clear_host_address(r->network, r->plen); } static gboolean @@ -632,7 +631,7 @@ _route_valid_6(const NMPlatformIP6Route *r) return r && r->plen <= 128 && (memcmp(&r->network, - nm_utils_ip6_address_clear_host_address(&n, &r->network, r->plen), + nm_ip6_addr_clear_host_address(&n, &r->network, r->plen), sizeof(n)) == 0); } @@ -2185,8 +2184,7 @@ _dedup_multi_index_cmp(const NML3ConfigData *a, NM_CMP_DIRECT(ra.metric, rb.metric); NM_CMP_DIRECT(ra.plen, rb.plen); - NM_CMP_RETURN_DIRECT( - nm_utils_ip4_address_same_prefix_cmp(ra.network, rb.network, ra.plen)); + NM_CMP_RETURN_DIRECT(nm_ip4_addr_same_prefix_cmp(ra.network, rb.network, ra.plen)); break; } case NMP_OBJECT_TYPE_IP6_ROUTE: @@ -2197,7 +2195,7 @@ _dedup_multi_index_cmp(const NML3ConfigData *a, NM_CMP_DIRECT(ra.metric, rb.metric); NM_CMP_DIRECT(ra.plen, rb.plen); NM_CMP_RETURN_DIRECT( - nm_utils_ip6_address_same_prefix_cmp(&ra.network, &rb.network, ra.plen)); + nm_ip6_addr_same_prefix_cmp(&ra.network, &rb.network, ra.plen)); break; } default: @@ -2298,8 +2296,7 @@ nm_l3_config_data_cmp_full(const NML3ConfigData *a, NM_CMP_DIRECT(ra.metric, rb.metric); NM_CMP_DIRECT(ra.plen, rb.plen); - NM_CMP_RETURN_DIRECT( - nm_utils_ip4_address_same_prefix_cmp(ra.network, rb.network, ra.plen)); + NM_CMP_RETURN_DIRECT(nm_ip4_addr_same_prefix_cmp(ra.network, rb.network, ra.plen)); } else { NMPlatformIP6Route ra = def_route_a->ip6_route; NMPlatformIP6Route rb = def_route_b->ip6_route; @@ -2307,7 +2304,7 @@ nm_l3_config_data_cmp_full(const NML3ConfigData *a, NM_CMP_DIRECT(ra.metric, rb.metric); NM_CMP_DIRECT(ra.plen, rb.plen); NM_CMP_RETURN_DIRECT( - nm_utils_ip6_address_same_prefix_cmp(&ra.network, &rb.network, ra.plen)); + nm_ip6_addr_same_prefix_cmp(&ra.network, &rb.network, ra.plen)); } } @@ -2425,10 +2422,7 @@ _data_get_direct_route_for_host(const NML3ConfigData *self, if (nm_platform_route_table_uncoerce(item->rx.table_coerced, TRUE) != route_table) continue; - if (!nm_utils_ip_address_same_prefix(addr_family, - host, - item->rx.network_ptr, - item->rx.plen)) + if (!nm_ip_addr_same_prefix(addr_family, host, item->rx.network_ptr, item->rx.plen)) continue; if (best_route && best_route->rx.metric <= item->rx.metric) @@ -2478,9 +2472,9 @@ nm_l3_config_data_get_blacklisted_ip4_routes(const NML3ConfigData *self, gboolea if (my_addr->plen == 0) continue; - network_4 = nm_utils_ip4_address_clear_host_address(my_addr->peer_address, my_addr->plen); + network_4 = nm_ip4_addr_clear_host_address(my_addr->peer_address, my_addr->plen); - if (nm_utils_ip4_address_is_zeronet(network_4)) { + if (nm_ip4_addr_is_zeronet(network_4)) { /* Kernel doesn't add device-routes for destinations that * start with 0.x.y.z. Skip them. */ continue; @@ -2672,9 +2666,9 @@ nm_l3_config_data_add_dependent_device_routes(NML3ConfigData *self, a6 = &addr_src->a6.peer_address; plen = 128; } else { - a6 = nm_utils_ip6_address_clear_host_address(&a6_stack, - &addr_src->a6.address, - addr_src->a6.plen); + a6 = nm_ip6_addr_clear_host_address(&a6_stack, + &addr_src->a6.address, + addr_src->a6.plen); plen = addr_src->a6.plen; } @@ -2819,7 +2813,7 @@ _init_from_connection_ip(NML3ConfigData *self, int addr_family, NMConnection *co plen = nm_ip_route_get_prefix(s_route); - nm_utils_ipx_address_clear_host_address(addr_family, &network_bin, &network_bin, plen); + nm_ip_addr_clear_host_address(addr_family, &network_bin, &network_bin, plen); if (IS_IPv4) { r.r4 = (NMPlatformIP4Route){ @@ -2854,7 +2848,7 @@ _init_from_connection_ip(NML3ConfigData *self, int addr_family, NMConnection *co NMIPAddr ip; s = nm_setting_ip_config_get_dns(s_ip, i); - if (!nm_utils_parse_inaddr_bin(addr_family, s, NULL, &ip)) + if (!nm_inet_parse_bin(addr_family, s, NULL, &ip)) continue; nm_l3_config_data_add_nameserver(self, addr_family, &ip); } diff --git a/src/core/nm-l3-ipv4ll.c b/src/core/nm-l3-ipv4ll.c index 3fc1e165f5..ec871befc7 100644 --- a/src/core/nm-l3-ipv4ll.c +++ b/src/core/nm-l3-ipv4ll.c @@ -104,17 +104,17 @@ NM_UTILS_ENUM2STR_DEFINE(nm_l3_ipv4ll_state_to_string, /*****************************************************************************/ -#define _ASSERT(self) \ - G_STMT_START \ - { \ - NML3IPv4LL *const _self = (self); \ - \ - nm_assert(NM_IS_L3_IPV4LL(_self)); \ - if (NM_MORE_ASSERTS > 5) { \ - nm_assert(_self->addr == 0u || nm_utils_ip4_address_is_link_local(_self->addr)); \ - nm_assert(!_self->l3cd || NM_IS_L3_CONFIG_DATA(_self->l3cd)); \ - } \ - } \ +#define _ASSERT(self) \ + G_STMT_START \ + { \ + NML3IPv4LL *const _self = (self); \ + \ + nm_assert(NM_IS_L3_IPV4LL(_self)); \ + if (NM_MORE_ASSERTS > 5) { \ + nm_assert(_self->addr == 0u || nm_ip4_addr_is_link_local(_self->addr)); \ + nm_assert(!_self->l3cd || NM_IS_L3_CONFIG_DATA(_self->l3cd)); \ + } \ + } \ G_STMT_END /*****************************************************************************/ @@ -290,7 +290,7 @@ _ip4_address_is_link_local(const NMPlatformIP4Address *a) { nm_assert(a); - return nm_utils_ip4_address_is_link_local(a->address) && a->plen == ADDR_IPV4LL_PREFIX_LEN + return nm_ip4_addr_is_link_local(a->address) && a->plen == ADDR_IPV4LL_PREFIX_LEN && a->address == a->peer_address; } @@ -322,7 +322,7 @@ _l3cd_config_create(int ifindex, in_addr_t addr, NMDedupMultiIndex *multi_idx) { nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; - nm_assert(nm_utils_ip4_address_is_link_local(addr)); + nm_assert(nm_ip4_addr_is_link_local(addr)); nm_assert(ifindex > 0); nm_assert(multi_idx); @@ -382,7 +382,7 @@ static void _ipv4ll_addrgen(NML3IPv4LL *self, gboolean generate_new_addr) { CSipHash state; - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; gboolean seed_changed = FALSE; in_addr_t addr_new; guint64 h; @@ -459,7 +459,7 @@ _ipv4ll_addrgen(NML3IPv4LL *self, gboolean generate_new_addr) if (!seed_changed && !generate_new_addr) { /* neither did the caller request a new address, nor was the seed changed. The current * address is still to be used. */ - nm_assert(nm_utils_ip4_address_is_link_local(self->addr)); + nm_assert(nm_ip4_addr_is_link_local(self->addr)); return; } @@ -492,9 +492,9 @@ gen_addr: if (self->addr == addr_new || NM_IN_SET(ntohl(addr_new) & 0x0000FF00u, 0x0000u, 0xFF00u)) goto gen_addr; - nm_assert(nm_utils_ip4_address_is_link_local(addr_new)); + nm_assert(nm_ip4_addr_is_link_local(addr_new)); - _LOGT("addr-gen: set address %s", _nm_utils_inet4_ntop(addr_new, sbuf_addr)); + _LOGT("addr-gen: set address %s", nm_inet4_ntop(addr_new, sbuf_addr)); self->addr = addr_new; } @@ -549,7 +549,7 @@ static void _l3cd_config_add(NML3IPv4LL *self) { nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; gboolean changed; _ASSERT(self); @@ -571,7 +571,7 @@ _l3cd_config_add(NML3IPv4LL *self) self->l3cd_timeout_msec_changed = FALSE; _LOGT("add l3cd config with %s (acd-timeout %u msec%s)", - _nm_utils_inet4_ntop(self->addr, sbuf_addr), + nm_inet4_ntop(self->addr, sbuf_addr), self->reg_timeout_msec, changed ? "" : " changed"); @@ -639,7 +639,7 @@ _ipv4ll_platform_ip4_address_lookup(NML3IPv4LL *self, in_addr_t addr) if (addr == 0u) return NULL; - nm_assert(nm_utils_ip4_address_is_link_local(addr)); + nm_assert(nm_ip4_addr_is_link_local(addr)); pladdr = nm_platform_ip4_address_get(nm_l3_ipv4ll_get_platform(self), nm_l3_ipv4ll_get_ifindex(self), @@ -658,7 +658,7 @@ _ipv4ll_l3cfg_get_acd_addr_info(NML3IPv4LL *self, in_addr_t addr) if (addr == 0u) return NULL; - nm_assert(nm_utils_ip4_address_is_link_local(addr)); + nm_assert(nm_ip4_addr_is_link_local(addr)); return nm_l3cfg_get_acd_addr_info(self->l3cfg, addr); } @@ -766,7 +766,7 @@ _ipv4ll_set_timed_out_update(NML3IPv4LL *self, TimedOutState new_state) static gboolean _ipv4ll_set_state(NML3IPv4LL *self, NML3IPv4LLState state) { - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; char sbuf100[100]; if (self->state == state) @@ -775,7 +775,7 @@ _ipv4ll_set_state(NML3IPv4LL *self, NML3IPv4LLState state) self->notify_on_idle = TRUE; _LOGT("state: set state %s (addr=%s)", nm_l3_ipv4ll_state_to_string(state, sbuf100, sizeof(sbuf100)), - _nm_utils_inet4_ntop(self->addr, sbuf_addr)); + nm_inet4_ntop(self->addr, sbuf_addr)); return TRUE; } diff --git a/src/core/nm-l3-ipv6ll.c b/src/core/nm-l3-ipv6ll.c index 2640c07554..1368e7fa4f 100644 --- a/src/core/nm-l3-ipv6ll.c +++ b/src/core/nm-l3-ipv6ll.c @@ -216,7 +216,7 @@ _emit_changed_on_idle_cb(gpointer user_data) _LOGT("emit changed signal (state=%s%s%s)", nm_l3_ipv6ll_state_to_string(state), lladdr ? ", " : "", - lladdr ? _nm_utils_inet6_ntop(lladdr, sbuf) : ""); + lladdr ? nm_inet6_ntop(lladdr, sbuf) : ""); self->notify_fcn(self, state, lladdr, self->user_data); @@ -525,14 +525,14 @@ _check(NML3IPv6LL *self) if (_pladdr_is_ll_tentative(pladdr)) { if (_set_cur_lladdr_obj(self, NM_L3_IPV6LL_STATE_DAD_IN_PROGRESS, pladdr)) { _LOGT("changed: waiting for address %s to complete DAD", - _nm_utils_inet6_ntop(&self->cur_lladdr, sbuf)); + nm_inet6_ntop(&self->cur_lladdr, sbuf)); _lladdr_handle_changed(self); } return; } if (_set_cur_lladdr_obj(self, NM_L3_IPV6LL_STATE_READY, pladdr)) { - _LOGT("changed: address %s is ready", _nm_utils_inet6_ntop(&self->cur_lladdr, sbuf)); + _LOGT("changed: address %s is ready", nm_inet6_ntop(&self->cur_lladdr, sbuf)); _lladdr_handle_changed(self); } return; @@ -545,9 +545,9 @@ _check(NML3IPv6LL *self) NM_IN_SET(self->state, NM_L3_IPV6LL_STATE_DAD_IN_PROGRESS, NM_L3_IPV6LL_STATE_READY)); if (self->state == NM_L3_IPV6LL_STATE_DAD_IN_PROGRESS) _LOGT("changed: address %s did not complete DAD", - _nm_utils_inet6_ntop(&self->cur_lladdr, sbuf)); + nm_inet6_ntop(&self->cur_lladdr, sbuf)); else { - _LOGT("changed: address %s is gone", _nm_utils_inet6_ntop(&self->cur_lladdr, sbuf)); + _LOGT("changed: address %s is gone", nm_inet6_ntop(&self->cur_lladdr, sbuf)); } /* reset the state here, so that we are sure that the following @@ -579,8 +579,7 @@ _check(NML3IPv6LL *self) * If that does not happen within timeout, we assume that this address failed DAD. */ self->wait_for_addr_source = nm_g_timeout_add_source(2000, _wait_for_addr_timeout_cb, self); if (_set_cur_lladdr_bin(self, NM_L3_IPV6LL_STATE_DAD_IN_PROGRESS, &lladdr)) { - _LOGT("changed: starting DAD for address %s", - _nm_utils_inet6_ntop(&self->cur_lladdr, sbuf)); + _LOGT("changed: starting DAD for address %s", nm_inet6_ntop(&self->cur_lladdr, sbuf)); _lladdr_handle_changed(self); } return; diff --git a/src/core/nm-l3cfg.c b/src/core/nm-l3cfg.c index b2fbb031a3..3c054b9ef8 100644 --- a/src/core/nm-l3cfg.c +++ b/src/core/nm-l3cfg.c @@ -358,16 +358,16 @@ G_DEFINE_TYPE(NML3Cfg, nm_l3cfg, G_TYPE_OBJECT) } \ G_STMT_END -#define _LOGT_acd(acd_data, ...) \ - G_STMT_START \ - { \ - char _sbuf_acd[NM_UTILS_INET_ADDRSTRLEN]; \ - \ - _LOGT("acd[%s, %s]: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ - _nm_utils_inet4_ntop((acd_data)->info.addr, _sbuf_acd), \ - _l3_acd_addr_state_to_string((acd_data)->info.state) \ - _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ - } \ +#define _LOGT_acd(acd_data, ...) \ + G_STMT_START \ + { \ + char _sbuf_acd[NM_INET_ADDRSTRLEN]; \ + \ + _LOGT("acd[%s, %s]: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ + nm_inet4_ntop((acd_data)->info.addr, _sbuf_acd), \ + _l3_acd_addr_state_to_string((acd_data)->info.state) \ + _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ + } \ G_STMT_END /*****************************************************************************/ @@ -548,7 +548,7 @@ _l3_config_notify_data_to_string(const NML3ConfigNotifyData *notify_data, char *sbuf, gsize sbuf_size) { - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; char sbuf100[100]; char sbufobf[NM_HASH_OBFUSCATE_PTR_STR_BUF_SIZE]; char *s = sbuf; @@ -577,7 +577,7 @@ _l3_config_notify_data_to_string(const NML3ConfigNotifyData *notify_data, nm_strbuf_append(&s, &l, ", addr=%s, state=%s", - _nm_utils_inet4_ntop(notify_data->acd_event.info.addr, sbuf_addr), + nm_inet4_ntop(notify_data->acd_event.info.addr, sbuf_addr), _l3_acd_addr_state_to_string(notify_data->acd_event.info.state)); break; case NM_L3_CONFIG_NOTIFY_TYPE_PLATFORM_CHANGE: @@ -603,7 +603,7 @@ _l3_config_notify_data_to_string(const NML3ConfigNotifyData *notify_data, &l, ", ipv4ll=" NM_HASH_OBFUSCATE_PTR_FMT "%s%s, state=%s", NM_HASH_OBFUSCATE_PTR(notify_data->ipv4ll_event.ipv4ll), - NM_PRINT_FMT_QUOTED2(addr4 != 0, ", addr=", _nm_utils_inet4_ntop(addr4, sbuf_addr), ""), + NM_PRINT_FMT_QUOTED2(addr4 != 0, ", addr=", nm_inet4_ntop(addr4, sbuf_addr), ""), nm_l3_ipv4ll_state_to_string(nm_l3_ipv4ll_get_state(notify_data->ipv4ll_event.ipv4ll), sbuf100, sizeof(sbuf100))); @@ -2230,7 +2230,7 @@ _l3_acd_data_state_change(NML3Cfg *self, gint64 now_msec; const char *log_reason; char sbuf256[256]; - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; if (!p_now_msec) { now_msec = 0; @@ -2550,7 +2550,7 @@ handle_init: if (!_l3_acd_data_defendconflict_warning_ratelimited(acd_data, p_now_msec)) { _LOGI("IPv4 address %s is used on network connected to interface %d%s%s%s from " "host %s", - _nm_utils_inet4_ntop(acd_data->info.addr, sbuf_addr), + nm_inet4_ntop(acd_data->info.addr, sbuf_addr), self->priv.ifindex, NM_PRINT_FMT_QUOTED(self->priv.plobj_next, " (", @@ -2565,7 +2565,7 @@ handle_init: nm_assert(acd_data->info.state == NM_L3_ACD_ADDR_STATE_DEFENDING); _LOGT_acd(acd_data, "address %s defended from %s", - _nm_utils_inet4_ntop(acd_data->info.addr, sbuf_addr), + nm_inet4_ntop(acd_data->info.addr, sbuf_addr), nm_ether_addr_to_string_a(sender_addr)); /* we just log an info message. Nothing else to do. */ return; @@ -2575,7 +2575,7 @@ handle_init: _LOGT_acd(acd_data, "address conflict for %s detected with %s", - _nm_utils_inet4_ntop(acd_data->info.addr, sbuf_addr), + nm_inet4_ntop(acd_data->info.addr, sbuf_addr), nm_ether_addr_to_string_a(sender_addr)); if (!_l3_acd_data_defendconflict_warning_ratelimited(acd_data, p_now_msec)) { @@ -2587,7 +2587,7 @@ handle_init: NMP_OBJECT_CAST_LINK(self->priv.plobj_next)->name, ")", ""), - _nm_utils_inet4_ntop(acd_data->info.addr, sbuf_addr), + nm_inet4_ntop(acd_data->info.addr, sbuf_addr), nm_ether_addr_to_string_a(sender_addr)); } @@ -4371,9 +4371,9 @@ _l3_commit_mptcp_af(NML3Cfg *self, default: if (IS_IPv4) { /* We take all addresses, including rfc1918 private addresses - * (nm_utils_ip_is_site_local()). */ + * (nm_ip_addr_is_site_local()). */ } else { - if (nm_utils_ip6_is_ula(&addr->a6.address)) { + if (nm_ip6_addr_is_ula(&addr->a6.address)) { /* Exclude unique local IPv6 addresses fc00::/7. */ goto skip_addr; } else { diff --git a/src/core/nm-netns.c b/src/core/nm-netns.c index 5ee6315292..81b7e2fc29 100644 --- a/src/core/nm-netns.c +++ b/src/core/nm-netns.c @@ -254,7 +254,7 @@ nm_netns_shared_ip_reserve(NMNetns *self) NMNetnsSharedIPHandle *handle; const in_addr_t addr_start = ntohl(0x0a2a0001u); /* 10.42.0.1 */ in_addr_t addr; - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; /* Find an unused address in the 10.42.x.x range */ @@ -284,10 +284,10 @@ nm_netns_shared_ip_reserve(NMNetns *self) if (count > 0xFFu) { if (handle->_ref_count == 1) { _LOGE("shared-ip4: ran out of shared IP addresses. Reuse %s/24", - _nm_utils_inet4_ntop(handle->addr, sbuf_addr)); + nm_inet4_ntop(handle->addr, sbuf_addr)); } else { _LOGD("shared-ip4: reserved IP address range %s/24 (duplicate)", - _nm_utils_inet4_ntop(handle->addr, sbuf_addr)); + nm_inet4_ntop(handle->addr, sbuf_addr)); } handle->_ref_count++; return handle; @@ -304,8 +304,7 @@ nm_netns_shared_ip_reserve(NMNetns *self) g_hash_table_add(priv->shared_ips, handle); - _LOGD("shared-ip4: reserved IP address range %s/24", - _nm_utils_inet4_ntop(handle->addr, sbuf_addr)); + _LOGD("shared-ip4: reserved IP address range %s/24", nm_inet4_ntop(handle->addr, sbuf_addr)); return handle; } @@ -314,7 +313,7 @@ nm_netns_shared_ip_release(NMNetnsSharedIPHandle *handle) { NMNetns *self; NMNetnsPrivate *priv; - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; g_return_if_fail(handle); @@ -331,7 +330,7 @@ nm_netns_shared_ip_release(NMNetnsSharedIPHandle *handle) nm_assert(handle->addr == ntohl(0x0A2AFF01u)); /* 10.42.255.1 */ handle->_ref_count--; _LOGD("shared-ip4: release IP address range %s/24 (%d more references held)", - _nm_utils_inet4_ntop(handle->addr, sbuf_addr), + nm_inet4_ntop(handle->addr, sbuf_addr), handle->_ref_count); return; } @@ -344,8 +343,7 @@ nm_netns_shared_ip_release(NMNetnsSharedIPHandle *handle) g_object_unref(self); } - _LOGD("shared-ip4: release IP address range %s/24", - _nm_utils_inet4_ntop(handle->addr, sbuf_addr)); + _LOGD("shared-ip4: release IP address range %s/24", nm_inet4_ntop(handle->addr, sbuf_addr)); handle->_self = NULL; nm_g_slice_free(handle); diff --git a/src/core/nm-pacrunner-manager.c b/src/core/nm-pacrunner-manager.c index 86a406326e..80db755fd7 100644 --- a/src/core/nm-pacrunner-manager.c +++ b/src/core/nm-pacrunner-manager.c @@ -129,7 +129,7 @@ get_ip_domains(GPtrArray *domains, const NML3ConfigData *l3cd, int addr_family) char *cidr; guint num; guint i; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; const NMPlatformIPAddress *address; const NMPlatformIPRoute *route; const char *const *strv; @@ -144,7 +144,7 @@ get_ip_domains(GPtrArray *domains, const NML3ConfigData *l3cd, int addr_family) nm_l3_config_data_iter_ip_address_for_each (&ipconf_iter, l3cd, addr_family, &address) { cidr = g_strdup_printf("%s/%u", - nm_utils_inet_ntop(addr_family, address->address_ptr, sbuf), + nm_inet_ntop(addr_family, address->address_ptr, sbuf), address->plen); g_ptr_array_add(domains, cidr); } @@ -153,7 +153,7 @@ get_ip_domains(GPtrArray *domains, const NML3ConfigData *l3cd, int addr_family) if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT(route)) continue; cidr = g_strdup_printf("%s/%u", - nm_utils_inet_ntop(addr_family, route->network_ptr, sbuf), + nm_inet_ntop(addr_family, route->network_ptr, sbuf), route->plen); g_ptr_array_add(domains, cidr); } diff --git a/src/core/nm-policy.c b/src/core/nm-policy.c index 16b0211fa2..5999bc0590 100644 --- a/src/core/nm-policy.c +++ b/src/core/nm-policy.c @@ -167,11 +167,11 @@ static void clear_ip6_prefix_delegation(gpointer data) { IP6PrefixDelegation *delegation = data; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; _LOGD(LOGD_IP6, "ipv6-pd: undelegating prefix %s/%d", - _nm_utils_inet6_ntop(&delegation->prefix.address, sbuf), + nm_inet6_ntop(&delegation->prefix.address, sbuf), delegation->prefix.plen); g_hash_table_foreach(delegation->subnets, _clear_ip6_subnet, NULL); @@ -204,7 +204,7 @@ ip6_subnet_from_delegation(IP6PrefixDelegation *delegation, NMDevice *device) { NMPlatformIP6Address *subnet; int ifindex = nm_device_get_ifindex(device); - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; subnet = g_hash_table_lookup(delegation->subnets, GINT_TO_POINTER(ifindex)); if (!subnet) { @@ -212,7 +212,7 @@ ip6_subnet_from_delegation(IP6PrefixDelegation *delegation, NMDevice *device) if (delegation->next_subnet >= (1 << (64 - delegation->prefix.plen))) { _LOGD(LOGD_IP6, "ipv6-pd: no more prefixes in %s/%d", - _nm_utils_inet6_ntop(&delegation->prefix.address, sbuf), + nm_inet6_ntop(&delegation->prefix.address, sbuf), delegation->prefix.plen); return FALSE; } @@ -241,7 +241,7 @@ ip6_subnet_from_delegation(IP6PrefixDelegation *delegation, NMDevice *device) _LOGD(LOGD_IP6, "ipv6-pd: %s allocated from a /%d prefix on %s", - _nm_utils_inet6_ntop(&subnet->address, sbuf), + nm_inet6_ntop(&subnet->address, sbuf), delegation->prefix.plen, nm_device_get_iface(device)); @@ -312,11 +312,11 @@ device_ip6_prefix_delegated(NMDevice *device, guint i; const CList *tmp_list; NMActiveConnection *ac; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; _LOGI(LOGD_IP6, "ipv6-pd: received a prefix %s/%d from %s", - _nm_utils_inet6_ntop(&prefix->address, sbuf), + nm_inet6_ntop(&prefix->address, sbuf), prefix->plen, nm_device_get_iface(device)); diff --git a/src/core/platform/nm-fake-platform.c b/src/core/platform/nm-fake-platform.c index a1ca5434cb..c0680fb10f 100644 --- a/src/core/platform/nm-fake-platform.c +++ b/src/core/platform/nm-fake-platform.c @@ -980,7 +980,7 @@ ipx_address_delete(NMPlatform *platform, || (plen && address->plen != *plen) || (peer_addr && (((peer_addr_i ^ address->peer_address) - & _nm_utils_ip4_prefix_to_netmask(address->plen)) + & nm_ip4_addr_netmask_from_prefix(address->plen)) != 0))) continue; } else { @@ -1151,8 +1151,8 @@ ip_route_add(NMPlatform *platform, &o) { if (addr_family == AF_INET) { const NMPlatformIP4Route *item = NMP_OBJECT_CAST_IP4_ROUTE(o); - guint32 n = nm_utils_ip4_address_clear_host_address(item->network, item->plen); - guint32 g = nm_utils_ip4_address_clear_host_address(r4->gateway, item->plen); + guint32 n = nm_ip4_addr_clear_host_address(item->network, item->plen); + guint32 g = nm_ip4_addr_clear_host_address(r4->gateway, item->plen); if (r->ifindex == item->ifindex && n == g) { has_route_to_gw = TRUE; @@ -1162,21 +1162,21 @@ ip_route_add(NMPlatform *platform, const NMPlatformIP6Route *item = NMP_OBJECT_CAST_IP6_ROUTE(o); if (r->ifindex == item->ifindex - && nm_utils_ip6_address_same_prefix(&r6->gateway, &item->network, item->plen)) { + && nm_ip6_addr_same_prefix(&r6->gateway, &item->network, item->plen)) { has_route_to_gw = TRUE; break; } } } if (!has_route_to_gw) { - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; if (addr_family == AF_INET) { nm_log_warn( LOGD_PLATFORM, "Fake platform: failure adding ip4-route '%d: %s/%d %d': Network Unreachable", r->ifindex, - _nm_utils_inet4_ntop(r4->network, sbuf), + nm_inet4_ntop(r4->network, sbuf), r->plen, r->metric); } else { @@ -1184,7 +1184,7 @@ ip_route_add(NMPlatform *platform, LOGD_PLATFORM, "Fake platform: failure adding ip6-route '%d: %s/%d %d': Network Unreachable", r->ifindex, - _nm_utils_inet6_ntop(&r6->network, sbuf), + nm_inet6_ntop(&r6->network, sbuf), r->plen, r->metric); } diff --git a/src/core/platform/tests/test-common.c b/src/core/platform/tests/test-common.c index 34ec5cc2c5..0a7b337762 100644 --- a/src/core/platform/tests/test-common.c +++ b/src/core/platform/tests/test-common.c @@ -217,13 +217,13 @@ _nmtstp_platform_ip_addresses_assert(const char *filename, } if (!addr_bin->found) { - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; g_error("%s:%d: IPv%c address %s was not found on ifindex %d", filename, lineno, nm_utils_addr_family_to_char(addr_bin->addr_family), - nm_utils_inet_ntop(addr_bin->addr_family, &addr_bin->addr, sbuf), + nm_inet_ntop(addr_bin->addr_family, &addr_bin->addr, sbuf), ifindex); } } @@ -582,7 +582,7 @@ _nmtstp_assert_ip4_route_exists(const char *file, r = _ip4_route_get(platform, ifindex, network, plen, metric, tos, &c); if (c != c_exists && c_exists != -1) { - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER g_error("[%s:%u] %s(): The ip4 route %s/%d metric %u tos %u shall exist %u times, but " @@ -590,7 +590,7 @@ _nmtstp_assert_ip4_route_exists(const char *file, file, line, func, - _nm_utils_inet4_ntop(network, sbuf), + nm_inet4_ntop(network, sbuf), plen, metric, tos, @@ -676,8 +676,8 @@ _nmtstp_assert_ip6_route_exists(const char *file, r = _ip6_route_get(platform, ifindex, network, plen, metric, src, src_plen, &c); if (c != c_exists && c_exists != -1) { - char s_src[NM_UTILS_INET_ADDRSTRLEN]; - char s_network[NM_UTILS_INET_ADDRSTRLEN]; + char s_src[NM_INET_ADDRSTRLEN]; + char s_network[NM_INET_ADDRSTRLEN]; NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER g_error("[%s:%u] %s(): The ip6 route %s/%d metric %u src %s/%d shall exist %u times, but " @@ -685,10 +685,10 @@ _nmtstp_assert_ip6_route_exists(const char *file, file, line, func, - _nm_utils_inet6_ntop(network, s_network), + nm_inet6_ntop(network, s_network), plen, metric, - _nm_utils_inet6_ntop(src, s_src), + nm_inet6_ntop(src, s_src), src_plen, c_exists, c); @@ -1051,8 +1051,8 @@ _ip_address_add(NMPlatform *platform, gs_free char *s_valid = NULL; gs_free char *s_preferred = NULL; gs_free char *s_label = NULL; - char b1[NM_UTILS_INET_ADDRSTRLEN]; - char b2[NM_UTILS_INET_ADDRSTRLEN]; + char b1[NM_INET_ADDRSTRLEN]; + char b2[NM_INET_ADDRSTRLEN]; ifname = nm_platform_link_get_name(platform, ifindex); g_assert(ifname); @@ -1065,18 +1065,18 @@ _ip_address_add(NMPlatform *platform, s_label = g_strdup_printf("%s:%s", ifname, label); if (is_v4) { - char s_peer[NM_UTILS_INET_ADDRSTRLEN + 50]; + char s_peer[NM_INET_ADDRSTRLEN + 50]; g_assert(flags == 0); if (peer_address->addr4 != address->addr4 || nmtst_get_rand_uint32() % 2) { /* If the peer is the same as the local address, we can omit it. The result should be identical */ - nm_sprintf_buf(s_peer, " peer %s", _nm_utils_inet4_ntop(peer_address->addr4, b2)); + nm_sprintf_buf(s_peer, " peer %s", nm_inet4_ntop(peer_address->addr4, b2)); } else s_peer[0] = '\0'; nmtstp_run_command_check("ip address change %s%s/%d dev %s%s%s%s", - _nm_utils_inet4_ntop(address->addr4, b1), + nm_inet4_ntop(address->addr4, b1), s_peer, plen, ifname, @@ -1089,10 +1089,10 @@ _ip_address_add(NMPlatform *platform, /* flags not implemented (yet) */ g_assert(flags == 0); nmtstp_run_command_check("ip address change %s%s%s/%d dev %s%s%s%s", - _nm_utils_inet6_ntop(&address->addr6, b1), + nm_inet6_ntop(&address->addr6, b1), !IN6_IS_ADDR_UNSPECIFIED(&peer_address->addr6) ? " peer " : "", !IN6_IS_ADDR_UNSPECIFIED(&peer_address->addr6) - ? _nm_utils_inet6_ntop(&peer_address->addr6, b2) + ? nm_inet6_ntop(&peer_address->addr6, b2) : "", plen, ifname, @@ -1299,8 +1299,8 @@ _ip_address_del(NMPlatform *platform, if (external_command) { const char *ifname; - char b1[NM_UTILS_INET_ADDRSTRLEN]; - char b2[NM_UTILS_INET_ADDRSTRLEN]; + char b1[NM_INET_ADDRSTRLEN]; + char b2[NM_INET_ADDRSTRLEN]; int success; gboolean had_address; @@ -1318,18 +1318,17 @@ _ip_address_del(NMPlatform *platform, had_address = !!nm_platform_ip6_address_get(platform, ifindex, &address->addr6); if (is_v4) { - success = nmtstp_run_command("ip address delete %s%s%s/%d dev %s", - _nm_utils_inet4_ntop(address->addr4, b1), - peer_address->addr4 != address->addr4 ? " peer " : "", - peer_address->addr4 != address->addr4 - ? _nm_utils_inet4_ntop(peer_address->addr4, b2) - : "", - plen, - ifname); + success = nmtstp_run_command( + "ip address delete %s%s%s/%d dev %s", + nm_inet4_ntop(address->addr4, b1), + peer_address->addr4 != address->addr4 ? " peer " : "", + peer_address->addr4 != address->addr4 ? nm_inet4_ntop(peer_address->addr4, b2) : "", + plen, + ifname); } else { g_assert(!peer_address); success = nmtstp_run_command("ip address delete %s/%d dev %s", - _nm_utils_inet6_ntop(&address->addr6, b1), + nm_inet6_ntop(&address->addr6, b1), plen, ifname); } @@ -1732,8 +1731,8 @@ nmtstp_link_gre_add(NMPlatform *platform, name, type, dev ?: "", - _nm_utils_inet4_ntop(lnk->local, b1), - _nm_utils_inet4_ntop(lnk->remote, b2), + nm_inet4_ntop(lnk->local, b1), + nm_inet4_ntop(lnk->remote, b2), lnk->ttl, lnk->tos, lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc"); @@ -1756,8 +1755,8 @@ nmtstp_link_ip6tnl_add(NMPlatform *platform, { const NMPlatformLink *pllink = NULL; gboolean success; - char b1[NM_UTILS_INET_ADDRSTRLEN]; - char b2[NM_UTILS_INET_ADDRSTRLEN]; + char b1[NM_INET_ADDRSTRLEN]; + char b2[NM_INET_ADDRSTRLEN]; char encap[20]; char tclass[20]; gboolean encap_ignore; @@ -1798,8 +1797,8 @@ nmtstp_link_ip6tnl_add(NMPlatform *platform, name, mode, dev, - _nm_utils_inet6_ntop(&lnk->local, b1), - _nm_utils_inet6_ntop(&lnk->remote, b2), + nm_inet6_ntop(&lnk->local, b1), + nm_inet6_ntop(&lnk->remote, b2), lnk->ttl, tclass_inherit ? "inherit" : nm_sprintf_buf(tclass, "%02x", lnk->tclass), encap_ignore ? "none" : nm_sprintf_buf(encap, "%u", lnk->encap_limit), @@ -1822,8 +1821,8 @@ nmtstp_link_ip6gre_add(NMPlatform *platform, { const NMPlatformLink *pllink = NULL; gboolean success; - char b1[NM_UTILS_INET_ADDRSTRLEN]; - char b2[NM_UTILS_INET_ADDRSTRLEN]; + char b1[NM_INET_ADDRSTRLEN]; + char b2[NM_INET_ADDRSTRLEN]; char tclass[20]; gboolean tclass_inherit; @@ -1848,8 +1847,8 @@ nmtstp_link_ip6gre_add(NMPlatform *platform, name, lnk->is_tap ? "ip6gretap" : "ip6gre", dev, - _nm_utils_inet6_ntop(&lnk->local, b1), - _nm_utils_inet6_ntop(&lnk->remote, b2), + nm_inet6_ntop(&lnk->local, b1), + nm_inet6_ntop(&lnk->remote, b2), lnk->ttl, tclass_inherit ? "inherit" : nm_sprintf_buf(tclass, "%02x", lnk->tclass), lnk->flow_label); @@ -1901,8 +1900,8 @@ nmtstp_link_ipip_add(NMPlatform *platform, "ip tunnel add %s mode ipip %s local %s remote %s ttl %u tos %02x %s", name, dev, - _nm_utils_inet4_ntop(lnk->local, b1), - _nm_utils_inet4_ntop(lnk->remote, b2), + nm_inet4_ntop(lnk->local, b1), + nm_inet4_ntop(lnk->remote, b2), lnk->ttl, lnk->tos, lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc"); @@ -1997,8 +1996,8 @@ nmtstp_link_sit_add(NMPlatform *platform, !nmtstp_run_command("ip tunnel add %s mode sit%s local %s remote %s ttl %u tos %02x %s", name, dev, - _nm_utils_inet4_ntop(lnk->local, b1), - _nm_utils_inet4_ntop(lnk->remote, b2), + nm_inet4_ntop(lnk->local, b1), + nm_inet4_ntop(lnk->remote, b2), lnk->ttl, lnk->tos, lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc"); @@ -2132,24 +2131,24 @@ nmtstp_link_vxlan_add(NMPlatform *platform, if (external_command) { gs_free char *dev = NULL; - char local[NM_UTILS_INET_ADDRSTRLEN]; - char group[NM_UTILS_INET_ADDRSTRLEN]; + char local[NM_INET_ADDRSTRLEN]; + char group[NM_INET_ADDRSTRLEN]; if (lnk->parent_ifindex) dev = g_strdup_printf("dev %s", nm_platform_link_get_name(platform, lnk->parent_ifindex)); if (lnk->local) - _nm_utils_inet4_ntop(lnk->local, local); + nm_inet4_ntop(lnk->local, local); else if (memcmp(&lnk->local6, &in6addr_any, sizeof(in6addr_any))) - _nm_utils_inet6_ntop(&lnk->local6, local); + nm_inet6_ntop(&lnk->local6, local); else local[0] = '\0'; if (lnk->group) - _nm_utils_inet4_ntop(lnk->group, group); + nm_inet4_ntop(lnk->group, group); else if (memcmp(&lnk->group6, &in6addr_any, sizeof(in6addr_any))) - _nm_utils_inet6_ntop(&lnk->group6, group); + nm_inet6_ntop(&lnk->group6, group); else group[0] = '\0'; @@ -2732,7 +2731,7 @@ nmtstp_acd_defender_new(int ifindex, in_addr_t ip_addr, const NMEtherAddr *mac_a NAcdProbe *probe = NULL; int fd; int r; - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; g_assert_cmpint(ifindex, >, 0); g_assert(mac_addr); @@ -2773,7 +2772,7 @@ nmtstp_acd_defender_new(int ifindex, in_addr_t ip_addr, const NMEtherAddr *mac_a NM_HASH_OBFUSCATE_PTR(defender), ifindex, NM_ETHER_ADDR_FORMAT_VAL(mac_addr), - _nm_utils_inet4_ntop(ip_addr, sbuf_addr)); + nm_inet4_ntop(ip_addr, sbuf_addr)); n_acd_probe_set_userdata(defender->probe, defender); diff --git a/src/core/platform/tests/test-link.c b/src/core/platform/tests/test-link.c index b72bcb65b2..29e75446ad 100644 --- a/src/core/platform/tests/test-link.c +++ b/src/core/platform/tests/test-link.c @@ -1183,7 +1183,7 @@ _test_wireguard_change(NMPlatform *platform, int ifindex, int test_mode) for (i = 0; i < num_peers; i++) { NMPWireGuardPeer peer; - char s_addr[NM_UTILS_INET_ADDRSTRLEN]; + char s_addr[NM_INET_ADDRSTRLEN]; NMSockAddrUnion endpoint; guint i_allowed_ips, n_allowed_ips; NMPWireGuardAllowedIP *allowed_ips; diff --git a/src/core/platform/tests/test-route.c b/src/core/platform/tests/test-route.c index 148ed7922d..ba8a626b95 100644 --- a/src/core/platform/tests/test-route.c +++ b/src/core/platform/tests/test-route.c @@ -27,7 +27,7 @@ _wait_for_ipv4_addr_device_route(NMPlatform *platform, /* Wait that the addresses gets a device-route. After adding a address, * the device route is not added immediately. It takes a moment... */ - addr = nm_utils_ip4_address_clear_host_address(addr, plen); + addr = nm_ip4_addr_clear_host_address(addr, plen); NMTST_WAIT_ASSERT(400, { NMDedupMultiIter iter; NMPLookup lookup; @@ -41,7 +41,7 @@ _wait_for_ipv4_addr_device_route(NMPlatform *platform, &o) { const NMPlatformIP4Route *r = NMP_OBJECT_CAST_IP4_ROUTE(o); - if (r->plen == plen && addr == nm_utils_ip4_address_clear_host_address(r->network, plen) + if (r->plen == plen && addr == nm_ip4_addr_clear_host_address(r->network, plen) && r->metric == 0 && r->scope_inv == nm_platform_route_scope_inv(RT_SCOPE_LINK) && r->rt_source == NM_IP_CONFIG_SOURCE_RTPROT_KERNEL) return; @@ -918,7 +918,7 @@ test_ip(gconstpointer test_data) const NMPlatformLink *l; char ifname[IFNAMSIZ]; char ifname2[IFNAMSIZ]; - char s1[NM_UTILS_INET_ADDRSTRLEN]; + char s1[NM_INET_ADDRSTRLEN]; NMPlatform *platform = NM_PLATFORM_GET; const int EX_ = -1; struct { @@ -1278,7 +1278,7 @@ _rule_create_random(NMPlatform *platform) guint32 p; int addr_size; guint i; - char saddr[NM_UTILS_INET_ADDRSTRLEN]; + char saddr[NM_INET_ADDRSTRLEN]; static struct { guint32 uid; guint32 euid; diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 6452d72a48..46df18b777 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -739,7 +739,7 @@ read_full_ip4_address(shvarFile *ifcfg, int prefix = 0; gboolean has_key; guint32 a; - char inet_buf[NM_UTILS_INET_ADDRSTRLEN]; + char inet_buf[NM_INET_ADDRSTRLEN]; g_return_val_if_fail(which >= -1, FALSE); g_return_val_if_fail(ifcfg != NULL, FALSE); @@ -761,7 +761,7 @@ read_full_ip4_address(shvarFile *ifcfg, if (!read_ip4_address(ifcfg, numbered_tag(tag, "GATEWAY", which), &has_key, &a, error)) return FALSE; if (has_key) - *out_gateway = nm_utils_inet4_ntop_dup(a); + *out_gateway = nm_inet4_ntop_dup(a); } /* Prefix */ @@ -782,16 +782,16 @@ read_full_ip4_address(shvarFile *ifcfg, if (!read_ip4_address(ifcfg, numbered_tag(tag, "NETMASK", which), &has_key, &a, error)) return FALSE; if (has_key) - prefix = _nm_utils_ip4_netmask_to_prefix(a); + prefix = nm_ip4_addr_netmask_to_prefix(a); else { if (base_addr) prefix = nm_ip_address_get_prefix(base_addr); else { /* Try to autodetermine the prefix for the address' class */ - prefix = _nm_utils_ip4_get_default_prefix(ipaddr); + prefix = nm_ip4_addr_get_default_prefix(ipaddr); PARSE_WARNING("missing %s, assuming %s/%d", prefix_tag, - _nm_utils_inet4_ntop(ipaddr, inet_buf), + nm_inet4_ntop(ipaddr, inet_buf), prefix); } } @@ -1282,7 +1282,7 @@ parse_line_type_addr_with_prefix: int prefix = -1; if (p_info->type == PARSE_LINE_TYPE_ADDR) { - if (!nm_utils_parse_inaddr_bin(addr_family, s, NULL, &p_data->v.addr.addr)) { + if (!nm_inet_parse_bin(addr_family, s, NULL, &p_data->v.addr.addr)) { if (p_info == &parse_infos[PARSE_LINE_ATTR_ROUTE_VIA] && nm_streq(s, "(null)")) { /* Due to a bug, would older versions of NM write "via (null)" @@ -1313,11 +1313,11 @@ parse_line_type_addr_with_prefix: if (p_info == &parse_infos[PARSE_LINE_ATTR_ROUTE_TO] && nm_streq(s, "default")) { memset(&p_data->v.addr.addr, 0, sizeof(p_data->v.addr.addr)); prefix = 0; - } else if (!nm_utils_parse_inaddr_prefix_bin(addr_family, - s, - NULL, - &p_data->v.addr.addr, - &prefix)) { + } else if (!nm_inet_parse_with_prefix_bin(addr_family, + s, + NULL, + &p_data->v.addr.addr, + &prefix)) { g_set_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, @@ -1468,7 +1468,7 @@ read_one_ip4_route(shvarFile *ifcfg, guint32 which, NMIPRoute **out_route, GErro const char *v; gs_free char *value = NULL; gint64 prefix, metric; - char inet_buf[NM_UTILS_INET_ADDRSTRLEN]; + char inet_buf[NM_INET_ADDRSTRLEN]; g_return_val_if_fail(ifcfg != NULL, FALSE); g_return_val_if_fail(out_route && !*out_route, FALSE); @@ -1496,14 +1496,14 @@ read_one_ip4_route(shvarFile *ifcfg, guint32 which, NMIPRoute **out_route, GErro error)) return FALSE; if (has_key) { - prefix = _nm_utils_ip4_netmask_to_prefix(netmask); - if (netmask != _nm_utils_ip4_prefix_to_netmask(prefix)) { + prefix = nm_ip4_addr_netmask_to_prefix(netmask); + if (netmask != nm_ip4_addr_netmask_from_prefix(prefix)) { g_set_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IP4 netmask '%s' \"%s\"", netmask_tag, - _nm_utils_inet4_ntop(netmask, inet_buf)); + nm_inet4_ntop(netmask, inet_buf)); return FALSE; } } else { @@ -1667,7 +1667,7 @@ parse_full_ip6_address(shvarFile *ifcfg, nm_assert(out_address && !*out_address); nm_assert(!error || !*error); - if (!nm_utils_parse_inaddr_prefix_bin(AF_INET6, addr_str, NULL, &addr_bin, &prefix)) { + if (!nm_inet_parse_with_prefix_bin(AF_INET6, addr_str, NULL, &addr_bin, &prefix)) { g_set_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, @@ -2027,7 +2027,7 @@ make_ip4_setting(shvarFile *ifcfg, "because the connection has no static addresses", f); } else - gateway = nm_utils_inet4_ntop_dup(a); + gateway = nm_inet4_ntop_dup(a); } } } @@ -2055,10 +2055,10 @@ make_ip4_setting(shvarFile *ifcfg, if (!v) break; - if (nm_utils_ipaddr_is_valid(AF_INET, v)) { + if (nm_inet_is_valid(AF_INET, v)) { if (!nm_setting_ip_config_add_dns(s_ip4, v)) PARSE_WARNING("duplicate DNS server %s", tag); - } else if (nm_utils_ipaddr_is_valid(AF_INET6, v)) { + } else if (nm_inet_is_valid(AF_INET6, v)) { /* Ignore IPv6 addresses */ } else { g_set_error(error, @@ -2546,7 +2546,7 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea if ((ptr = strchr(v, '%')) != NULL) *ptr = '\0'; /* remove %interface prefix if present */ - if (!nm_utils_ipaddr_is_valid(AF_INET6, v)) { + if (!nm_inet_is_valid(AF_INET6, v)) { if (!is_disabled) { g_set_error(error, NM_SETTINGS_ERROR, @@ -2594,14 +2594,14 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea if (!v) break; - if (nm_utils_ipaddr_is_valid(AF_INET6, v)) { + if (nm_inet_is_valid(AF_INET6, v)) { if (is_disabled) { PARSE_WARNING("ignore DNS server addresses with method disabled/ignore"); break; } if (!nm_setting_ip_config_add_dns(s_ip6, v)) PARSE_WARNING("duplicate DNS server %s", tag); - } else if (nm_utils_ipaddr_is_valid(AF_INET, v)) { + } else if (nm_inet_is_valid(AF_INET, v)) { /* Ignore IPv4 addresses */ } else { if (is_disabled) diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index 96efc9e5d7..d8c6a839f0 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -2409,8 +2409,8 @@ write_route_file_svformat(const char *filename, NMSettingIPConfig *s_ip4) svSetValueStr(routefile, addr_key, nm_ip_route_get_dest(route)); - netmask = _nm_utils_ip4_prefix_to_netmask(nm_ip_route_get_prefix(route)); - svSetValueStr(routefile, netmask_key, _nm_utils_inet4_ntop(netmask, buf)); + netmask = nm_ip4_addr_netmask_from_prefix(nm_ip_route_get_prefix(route)); + svSetValueStr(routefile, netmask_key, nm_inet4_ntop(netmask, buf)); svSetValueStr(routefile, gw_key, nm_ip_route_get_next_hop(route)); @@ -2819,9 +2819,7 @@ write_ip4_setting(NMConnection *connection, if (has_netmask) { char buf[INET_ADDRSTRLEN]; - svSetValueStr(ifcfg, - tag, - _nm_utils_inet4_ntop(_nm_utils_ip4_prefix_to_netmask(prefix), buf)); + svSetValueStr(ifcfg, tag, nm_inet4_ntop(nm_ip4_addr_netmask_from_prefix(prefix), buf)); } n++; diff --git a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 9fdae4bd25..0ba9dc6b23 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -2082,7 +2082,7 @@ test_read_wired_aliases_good(gconstpointer test_data) g_assert(ip4_addr != NULL); addr = nm_ip_address_get_address(ip4_addr); - g_assert(nm_utils_ipaddr_is_valid(AF_INET, addr)); + g_assert(nm_inet_is_valid(AF_INET, addr)); for (j = 0; j < expected_num_addresses; j++) { if (!g_strcmp0(addr, expected_address[j])) diff --git a/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c b/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c index a1d6781b41..3bdd78c9a5 100644 --- a/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c +++ b/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c @@ -451,7 +451,7 @@ update_ip4_setting_from_if_block(NMConnection *connection, if_block *block, GErr netmask_v); return FALSE; } else { - netmask_int = _nm_utils_ip4_netmask_to_prefix(tmp_mask); + netmask_int = nm_ip4_addr_netmask_to_prefix(tmp_mask); } } @@ -470,7 +470,7 @@ update_ip4_setting_from_if_block(NMConnection *connection, if_block *block, GErr /* gateway */ gateway_v = ifparser_getkey(block, "gateway"); if (gateway_v) { - if (!nm_utils_ipaddr_is_valid(AF_INET, gateway_v)) { + if (!nm_inet_is_valid(AF_INET, gateway_v)) { g_set_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, @@ -579,7 +579,7 @@ update_ip6_setting_from_if_block(NMConnection *connection, if_block *block, GErr gateway_v = ifparser_getkey(block, "gateway"); if (gateway_v) { - if (!nm_utils_ipaddr_is_valid(AF_INET6, gateway_v)) { + if (!nm_inet_is_valid(AF_INET6, gateway_v)) { g_set_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, diff --git a/src/core/supplicant/nm-supplicant-interface.c b/src/core/supplicant/nm-supplicant-interface.c index fa8b4e3713..5b5d86229c 100644 --- a/src/core/supplicant/nm-supplicant-interface.c +++ b/src/core/supplicant/nm-supplicant-interface.c @@ -3174,7 +3174,7 @@ _signal_handle(NMSupplicantInterface *self, _set_p2p_assigned_addr(iface, addr_data, - _nm_utils_ip4_netmask_to_prefix(netmask)); + nm_ip4_addr_netmask_to_prefix(netmask)); } else { _LOGW("P2P: GroupStarted signaled invalid IP Address information"); } diff --git a/src/core/tests/test-core.c b/src/core/tests/test-core.c index c260788e1a..07309518f1 100644 --- a/src/core/tests/test-core.c +++ b/src/core/tests/test-core.c @@ -40,7 +40,7 @@ test_config_h(void) /*****************************************************************************/ -/* Reference implementation for nm_utils_ip6_address_clear_host_address. +/* Reference implementation for nm_ip6_addr_clear_host_address. * Taken originally from set_address_masked(), src/ndisc/nm-lndp-ndisc.c **/ static void @@ -95,14 +95,14 @@ test_nm_utils_ip6_address_clear_host_address(void) _randomize_in6_addr(&addr1, r); _randomize_in6_addr(&addr2, r); addr1 = addr_src; - nm_utils_ip6_address_clear_host_address(&addr2, &addr1, plen); + nm_ip6_addr_clear_host_address(&addr2, &addr1, plen); g_assert_cmpint(memcmp(&addr1, &addr_src, sizeof(struct in6_addr)), ==, 0); g_assert_cmpint(memcmp(&addr2, &addr_ref, sizeof(struct in6_addr)), ==, 0); /* test for self assignment/inplace update. */ _randomize_in6_addr(&addr1, r); addr1 = addr_src; - nm_utils_ip6_address_clear_host_address(&addr1, &addr1, plen); + nm_ip6_addr_clear_host_address(&addr1, &addr1, plen); g_assert_cmpint(memcmp(&addr1, &addr_ref, sizeof(struct in6_addr)), ==, 0); } } @@ -155,11 +155,11 @@ _test_same_prefix(const char *a1, const char *a2, guint8 plen) struct in6_addr a = *nmtst_inet6_from_string(a1); struct in6_addr b = *nmtst_inet6_from_string(a2); - g_assert(nm_utils_ip6_address_same_prefix(&a, &b, plen)); + g_assert(nm_ip6_addr_same_prefix(&a, &b, plen)); } static void -test_nm_utils_ip6_address_same_prefix(void) +test_nm_ip_addr_same_prefix(void) { guint n, i; const guint N = 100; @@ -202,7 +202,7 @@ again_plen: } else b = a; - result = nm_utils_ip6_address_same_prefix(&a.val, &b.val, plen); + result = nm_ip6_addr_same_prefix(&a.val, &b.val, plen); g_assert(result == is_same); g_assert(NM_IN_SET(result, TRUE, FALSE)); } @@ -214,12 +214,12 @@ again_plen: plen = nmtst_get_rand_uint32() % 129; memset(addrmask.ptr, 0xFF, sizeof(addrmask)); - nm_utils_ip6_address_clear_host_address(&addrmask.val, &addrmask.val, plen); + nm_ip6_addr_clear_host_address(&addrmask.val, &addrmask.val, plen); for (i = 0; i < sizeof(a); i++) b.ptr[i] = (a.ptr[i] & addrmask.ptr[i]) | (b.ptr[i] & ~addrmask.ptr[i]); - g_assert(nm_utils_ip6_address_same_prefix(&a.val, &b.val, plen) == TRUE); + g_assert(nm_ip6_addr_same_prefix(&a.val, &b.val, plen) == TRUE); } /* test#3 */ @@ -234,10 +234,10 @@ again_plen: continue; memset(addrmask.ptr, 0xFF, sizeof(addrmask)); - nm_utils_ip6_address_clear_host_address(&addrmask.val, &addrmask.val, plen); + nm_ip6_addr_clear_host_address(&addrmask.val, &addrmask.val, plen); memset(addrmask_bit.ptr, 0xFF, sizeof(addrmask_bit)); - nm_utils_ip6_address_clear_host_address(&addrmask_bit.val, &addrmask_bit.val, plen - 1); + nm_ip6_addr_clear_host_address(&addrmask_bit.val, &addrmask_bit.val, plen - 1); for (i = 0; i < sizeof(a); i++) b.ptr[i] = (a.ptr[i] & addrmask.ptr[i]) | (b.ptr[i] & ~addrmask.ptr[i]); @@ -254,7 +254,7 @@ again_plen: } g_assert(reached); - g_assert(nm_utils_ip6_address_same_prefix(&a.val, &b.val, plen) == FALSE); + g_assert(nm_ip6_addr_same_prefix(&a.val, &b.val, plen) == FALSE); } /* test#4 */ @@ -2594,10 +2594,9 @@ main(int argc, char **argv) g_test_add_func("/general/nm_strbuf_append", test_nm_utils_strbuf_append); - g_test_add_func("/general/nm_utils_ip6_address_clear_host_address", + g_test_add_func("/general/nm_ip6_addr_clear_host_address", test_nm_utils_ip6_address_clear_host_address); - g_test_add_func("/general/nm_utils_ip6_address_same_prefix", - test_nm_utils_ip6_address_same_prefix); + g_test_add_func("/general/nm_ip6_addr_same_prefix", test_nm_ip_addr_same_prefix); g_test_add_func("/general/nm_utils_log_connection_diff", test_nm_utils_log_connection_diff); g_test_add_func("/general/nm_utils_sysctl_ip_conf_path", test_nm_utils_sysctl_ip_conf_path); diff --git a/src/core/tests/test-l3cfg.c b/src/core/tests/test-l3cfg.c index a9ac400496..67c030197a 100644 --- a/src/core/tests/test-l3cfg.c +++ b/src/core/tests/test-l3cfg.c @@ -572,7 +572,7 @@ _test_l3_ipv4ll_signal_notify(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, TestL3IPv4LLData *tdata) { - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; g_assert(NM_IS_L3CFG(l3cfg)); g_assert(tdata); @@ -593,9 +593,9 @@ _test_l3_ipv4ll_signal_notify(NML3Cfg *l3cfg, if (tdata->f->test_idx == 2 && nmtst_get_rand_bool()) { tdata->addr_commit++; tdata->addr_commit_addr = nm_l3_ipv4ll_get_addr(tdata->l3ipv4ll); - g_assert(nm_utils_ip4_address_is_link_local(tdata->addr_commit_addr)); + g_assert(nm_ip4_addr_is_link_local(tdata->addr_commit_addr)); _LOGT("add address %s that passed ACD", - _nm_utils_inet4_ntop(tdata->addr_commit_addr, sbuf_addr)); + nm_inet4_ntop(tdata->addr_commit_addr, sbuf_addr)); if (!nm_l3cfg_add_config(nm_l3_ipv4ll_get_l3cfg(tdata->l3ipv4ll), TEST_L3_IPV4LL_TAG(tdata, 1), nmtst_get_rand_bool(), @@ -630,9 +630,9 @@ _test_l3_ipv4ll_signal_notify(NML3Cfg *l3cfg, if (tdata->addr_commit > 0) { g_assert_cmpint(tdata->addr_commit, ==, 1); tdata->addr_commit--; - g_assert(nm_utils_ip4_address_is_link_local(tdata->addr_commit_addr)); + g_assert(nm_ip4_addr_is_link_local(tdata->addr_commit_addr)); _LOGT("remove address %s that previously passed ACD", - _nm_utils_inet4_ntop(tdata->addr_commit_addr, sbuf_addr)); + nm_inet4_ntop(tdata->addr_commit_addr, sbuf_addr)); if (!nm_l3cfg_remove_config_all(nm_l3_ipv4ll_get_l3cfg(tdata->l3ipv4ll), TEST_L3_IPV4LL_TAG(tdata, 1))) g_assert_not_reached(); @@ -663,7 +663,7 @@ test_l3_ipv4ll(gconstpointer test_data) gint64 start_time_msec; gint64 total_poll_time_msec; nm_auto_remove_l3ipv4ll_registration NML3IPv4LLRegistration *l3ipv4ll_reg = NULL; - char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf_addr[NM_INET_ADDRSTRLEN]; _LOGD("test start (/l3-ipv4ll/%d)", TEST_IDX); @@ -733,12 +733,12 @@ test_l3_ipv4ll(gconstpointer test_data) if (tdata->f->test_idx == 2 && nmtst_get_rand_one_case_in(3)) { in_addr_t a = nm_l3_ipv4ll_get_addr(l3ipv4ll); - g_assert(nm_utils_ip4_address_is_link_local(a)); + g_assert(nm_ip4_addr_is_link_local(a)); _test_l3_ipv4ll_maybe_add_addr_4(tdata, tdata->f->ifindex1, 2, &tdata->add_conflict_done, - _nm_utils_inet4_ntop(a, sbuf_addr)); + nm_inet4_ntop(a, sbuf_addr)); g_assert_cmpint(tdata->f->hwaddr1.len, ==, sizeof(NMEtherAddr)); acd_defender_2 = nmtstp_acd_defender_new(tdata->f->ifindex1, a, &tdata->f->hwaddr1.ether_addr); @@ -768,12 +768,11 @@ test_l3_ipv4ll(gconstpointer test_data) if (tdata->addr_commit == 1 && !tdata->add_conflict_checked) { tdata->add_conflict_checked = TRUE; - _test_l3_ipv4ll_maybe_add_addr_4( - tdata, - tdata->f->ifindex1, - 2, - &tdata->add_conflict_done, - _nm_utils_inet4_ntop(tdata->addr_commit_addr, sbuf_addr)); + _test_l3_ipv4ll_maybe_add_addr_4(tdata, + tdata->f->ifindex1, + 2, + &tdata->add_conflict_done, + nm_inet4_ntop(tdata->addr_commit_addr, sbuf_addr)); if (tdata->add_conflict_done) total_poll_time_msec += L3IPV4LL_ACD_TIMEOUT_MSEC / 2; g_assert_cmpint(tdata->f->hwaddr1.len, ==, sizeof(NMEtherAddr)); diff --git a/src/core/vpn/nm-vpn-connection.c b/src/core/vpn/nm-vpn-connection.c index bbb7355016..860b3086d3 100644 --- a/src/core/vpn/nm-vpn-connection.c +++ b/src/core/vpn/nm-vpn-connection.c @@ -1217,7 +1217,7 @@ _parent_device_l3cd_add_gateway_route(NML3ConfigData *l3cd, if (!nm_ip_addr_is_null(addr_family, gw)) { nm_ip_addr_set(addr_family, &parent_gw, gw); has_parent_gw = TRUE; - } else if (nm_utils_ip_is_site_local(addr_family, vpn_gw)) + } else if (nm_ip_addr_is_site_local(addr_family, vpn_gw)) has_parent_gw = TRUE; else if ((obj = nm_device_get_best_default_route(parent_device, addr_family)) && nm_ip_addr_is_null( @@ -2104,9 +2104,8 @@ _dbus_signal_ip_config_cb(NMVpnConnection *self, int addr_family, GVariant *dict if (plen > 32) break; - route.r4.plen = plen; - route.r4.network = - nm_utils_ip4_address_clear_host_address(route.r4.network, plen); + route.r4.plen = plen; + route.r4.network = nm_ip4_addr_clear_host_address(route.r4.network, plen); if (priv->ip_data_4.gw_external.addr4 && route.r4.network == priv->ip_data_4.gw_external.addr4 @@ -2146,9 +2145,7 @@ _dbus_signal_ip_config_cb(NMVpnConnection *self, int addr_family, GVariant *dict nm_ip_addr_set_from_variant(AF_INET6, &route.r6.gateway, next_hop, NULL); - nm_utils_ip6_address_clear_host_address(&route.r6.network, - &route.r6.network, - route.r6.plen); + nm_ip6_addr_clear_host_address(&route.r6.network, &route.r6.network, route.r6.plen); if (!IN6_IS_ADDR_UNSPECIFIED(&priv->ip_data_6.gw_external.addr6) && IN6_ARE_ADDR_EQUAL(&route.r6.network, &priv->ip_data_6.gw_external.addr6) diff --git a/src/libnm-client-impl/nm-conn-utils.c b/src/libnm-client-impl/nm-conn-utils.c index 5d04cd32d9..5cfa26b830 100644 --- a/src/libnm-client-impl/nm-conn-utils.c +++ b/src/libnm-client-impl/nm-conn-utils.c @@ -271,11 +271,11 @@ nm_conn_wireguard_import(const char *filename, GError **error) int addr_family; int prefix_len; - if (!nm_utils_parse_inaddr_prefix_bin(AF_UNSPEC, - value_word, - &addr_family, - &addr_bin, - &prefix_len)) + if (!nm_inet_parse_with_prefix_bin(AF_UNSPEC, + value_word, + &addr_family, + &addr_bin, + &prefix_len)) goto fail_invalid_value; p_data_addr = (addr_family == AF_INET) ? &data_addr_v4 : &data_addr_v6; @@ -315,13 +315,12 @@ nm_conn_wireguard_import(const char *filename, GError **error) NMIPAddr addr_bin; int addr_family; - if (nm_utils_parse_inaddr_bin(AF_UNSPEC, value_word, &addr_family, &addr_bin)) { + if (nm_inet_parse_bin(AF_UNSPEC, value_word, &addr_family, &addr_bin)) { p_data_dns = (addr_family == AF_INET) ? &data_dns_v4 : &data_dns_v6; if (!*p_data_dns) *p_data_dns = g_ptr_array_new_with_free_func(g_free); - g_ptr_array_add(*p_data_dns, - nm_utils_inet_ntop_dup(addr_family, &addr_bin)); + g_ptr_array_add(*p_data_dns, nm_inet_ntop_dup(addr_family, &addr_bin)); continue; } diff --git a/src/libnm-client-impl/nm-ip-config.c b/src/libnm-client-impl/nm-ip-config.c index 2307ce2c73..9aa2e778ce 100644 --- a/src/libnm-client-impl/nm-ip-config.c +++ b/src/libnm-client-impl/nm-ip-config.c @@ -175,9 +175,7 @@ _notify_update_prop_nameservers(NMClient *client, if (!g_variant_is_of_type(val, G_VARIANT_TYPE_STRING)) goto next; - if (!nm_utils_parse_inaddr(AF_INET, - g_variant_get_string(val, NULL), - &val_str)) + if (!nm_inet_parse_str(AF_INET, g_variant_get_string(val, NULL), &val_str)) goto next; if (!arr) arr = g_ptr_array_new(); diff --git a/src/libnm-core-impl/nm-connection.c b/src/libnm-core-impl/nm-connection.c index aed4be2113..5a46226559 100644 --- a/src/libnm-core-impl/nm-connection.c +++ b/src/libnm-core-impl/nm-connection.c @@ -1306,11 +1306,11 @@ _normalize_ip_config(NMConnection *self, GHashTable *parameters) && nm_setting_ip6_config_get_addr_gen_mode((NMSettingIP6Config *) s_ip6) == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64) { struct in6_addr i6_token; - char normalized[NM_UTILS_INET_ADDRSTRLEN]; + char normalized[NM_INET_ADDRSTRLEN]; if (inet_pton(AF_INET6, token, &i6_token) == 1 && _nm_utils_inet6_is_token(&i6_token)) { - _nm_utils_inet6_ntop(&i6_token, normalized); + nm_inet6_ntop(&i6_token, normalized); if (g_strcmp0(token, normalized)) { g_object_set(s_ip6, NM_SETTING_IP6_CONFIG_TOKEN, normalized, NULL); changed = TRUE; diff --git a/src/libnm-core-impl/nm-keyfile.c b/src/libnm-core-impl/nm-keyfile.c index 6ee68b5c4b..8201940895 100644 --- a/src/libnm-core-impl/nm-keyfile.c +++ b/src/libnm-core-impl/nm-keyfile.c @@ -397,7 +397,7 @@ build_route(KeyfileReaderInfo *info, /* Next hop */ if (gateway_str && gateway_str[0]) { - if (!nm_utils_ipaddr_is_valid(family, gateway_str)) { + if (!nm_inet_is_valid(family, gateway_str)) { /* Try workaround for routes written by broken keyfile writer. * Due to bug bgo#719851, an older version of writer would have * written "a:b:c:d::/plen,metric" if the gateway was ::, instead @@ -3692,7 +3692,7 @@ _read_setting_wireguard_peer(KeyfileReaderInfo *info) gsize i; for (i = 0; i < n_sa; i++) { - if (!nm_utils_parse_inaddr_prefix_bin(AF_UNSPEC, sa[i], NULL, NULL, NULL)) { + if (!nm_inet_parse_with_prefix_bin(AF_UNSPEC, sa[i], NULL, NULL, NULL)) { has_error = TRUE; continue; } diff --git a/src/libnm-core-impl/nm-setting-bond.c b/src/libnm-core-impl/nm-setting-bond.c index cdfc764187..230b2785ac 100644 --- a/src/libnm-core-impl/nm-setting-bond.c +++ b/src/libnm-core-impl/nm-setting-bond.c @@ -506,7 +506,7 @@ validate_ip(const char *name, const char *value, GError **error) return FALSE; } for (i = 0; addrs[i]; i++) { - if (!nm_utils_parse_inaddr_bin(AF_INET, addrs[i], NULL, NULL)) { + if (!nm_inet_parse_bin(AF_INET, addrs[i], NULL, NULL)) { g_set_error(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index 916a803806..cafdcd2b4a 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -67,7 +67,7 @@ canonicalize_ip_binary(int family, const NMIPAddr *ip, gboolean null_any) if (null_any && nm_ip_addr_is_null(family, ip)) return NULL; - return nm_utils_inet_ntop_dup(family, ip); + return nm_inet_ntop_dup(family, ip); } static gboolean @@ -80,7 +80,7 @@ valid_ip(int family, const char *ip, NMIPAddr *addr, GError **error) family == AF_INET ? _("Missing IPv4 address") : _("Missing IPv6 address")); return FALSE; } - if (!nm_utils_parse_inaddr_bin(family, ip, NULL, addr)) { + if (!nm_inet_parse_bin(family, ip, NULL, addr)) { g_set_error(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED, @@ -210,7 +210,7 @@ nm_ip_address_new_binary(int family, gconstpointer addr, guint prefix, GError ** *address = (NMIPAddress){ .refcount = 1, .family = family, - .address = nm_utils_inet_ntop_dup(family, addr), + .address = nm_inet_ntop_dup(family, addr), .prefix = prefix, }; @@ -418,7 +418,7 @@ nm_ip_address_set_address(NMIPAddress *address, const char *addr) if (!valid_ip(address->family, addr, &addr_bin, NULL)) { g_return_if_fail(addr != NULL); - g_return_if_fail(nm_utils_ipaddr_is_valid(address->family, addr)); + g_return_if_fail(nm_inet_is_valid(address->family, addr)); nm_assert_not_reached(); } @@ -460,7 +460,7 @@ nm_ip_address_set_address_binary(NMIPAddress *address, gconstpointer addr) g_return_if_fail(addr != NULL); g_free(address->address); - address->address = nm_utils_inet_ntop_dup(address->family, addr); + address->address = nm_inet_ntop_dup(address->family, addr); } /** @@ -883,7 +883,7 @@ nm_ip_route_get_dest(NMIPRoute *route) * Sets the destination property of this route object. * * @dest must be a valid address of @route's family. If you aren't sure you - * have a valid address, use nm_utils_ipaddr_is_valid() to check it. + * have a valid address, use nm_inet_is_valid() to check it. **/ void nm_ip_route_set_dest(NMIPRoute *route, const char *dest) @@ -893,7 +893,7 @@ nm_ip_route_set_dest(NMIPRoute *route, const char *dest) g_return_if_fail(route != NULL); if (!valid_ip(route->family, dest, &dest_bin, NULL)) { - g_return_if_fail(nm_utils_ipaddr_is_valid(route->family, dest)); + g_return_if_fail(nm_inet_is_valid(route->family, dest)); nm_assert_not_reached(); } @@ -935,7 +935,7 @@ nm_ip_route_set_dest_binary(NMIPRoute *route, gconstpointer dest) g_return_if_fail(dest != NULL); g_free(route->dest); - route->dest = nm_utils_inet_ntop_dup(route->family, dest); + route->dest = nm_inet_ntop_dup(route->family, dest); } /** @@ -1008,7 +1008,7 @@ nm_ip_route_set_next_hop(NMIPRoute *route, const char *next_hop) g_return_if_fail(route != NULL); if (next_hop && !valid_ip(route->family, next_hop, &next_hop_bin, NULL)) { - g_return_if_fail(!next_hop || nm_utils_ipaddr_is_valid(route->family, next_hop)); + g_return_if_fail(!next_hop || nm_inet_is_valid(route->family, next_hop)); nm_assert_not_reached(); } @@ -1352,7 +1352,7 @@ _ip_route_attribute_validate(const char *name, switch (spec->type_detail) { case 'a': /* IP address */ string = g_variant_get_string(value, NULL); - if (!nm_utils_ipaddr_is_valid(family, string)) { + if (!nm_inet_is_valid(family, string)) { g_set_error(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED, @@ -1384,7 +1384,7 @@ _ip_route_attribute_validate(const char *name, return FALSE; } } - if (!nm_utils_ipaddr_is_valid(family, addr)) { + if (!nm_inet_is_valid(family, addr)) { g_set_error(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED, @@ -1911,7 +1911,7 @@ nm_ip_routing_rule_get_from(const NMIPRoutingRule *self) if (!self->from_str) { nm_assert(self->from_valid); ((NMIPRoutingRule *) self)->from_str = - nm_utils_inet_ntop_dup(_ip_routing_rule_get_addr_family(self), &self->from_bin); + nm_inet_ntop_dup(_ip_routing_rule_get_addr_family(self), &self->from_bin); } return self->from_str; } @@ -1968,12 +1968,10 @@ nm_ip_routing_rule_set_from(NMIPRoutingRule *self, const char *from, guint8 len) } nm_clear_g_free(&self->from_str); - self->from_has = TRUE; - self->from_len = len; - self->from_valid = nm_utils_parse_inaddr_bin(_ip_routing_rule_get_addr_family(self), - from, - NULL, - &self->from_bin); + self->from_has = TRUE; + self->from_len = len; + self->from_valid = + nm_inet_parse_bin(_ip_routing_rule_get_addr_family(self), from, NULL, &self->from_bin); if (!self->from_valid) self->from_str = g_strdup(from); } @@ -2013,7 +2011,7 @@ nm_ip_routing_rule_get_to(const NMIPRoutingRule *self) if (!self->to_str) { nm_assert(self->to_valid); ((NMIPRoutingRule *) self)->to_str = - nm_utils_inet_ntop_dup(_ip_routing_rule_get_addr_family(self), &self->to_bin); + nm_inet_ntop_dup(_ip_routing_rule_get_addr_family(self), &self->to_bin); } return self->to_str; } @@ -2074,7 +2072,7 @@ nm_ip_routing_rule_set_to(NMIPRoutingRule *self, const char *to, guint8 len) self->to_has = TRUE; self->to_len = len; self->to_valid = - nm_utils_parse_inaddr_bin(_ip_routing_rule_get_addr_family(self), to, NULL, &self->to_bin); + nm_inet_parse_bin(_ip_routing_rule_get_addr_family(self), to, NULL, &self->to_bin); if (!self->to_valid) self->to_str = g_strdup(to); } @@ -3167,7 +3165,7 @@ GVariant * nm_ip_routing_rule_to_dbus(const NMIPRoutingRule *self) { GVariantBuilder builder; - char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + char addr_str[NM_INET_ADDRSTRLEN]; g_return_val_if_fail(NM_IS_IP_ROUTING_RULE(self, TRUE), NULL); @@ -3220,9 +3218,9 @@ nm_ip_routing_rule_to_dbus(const NMIPRoutingRule *self) &builder, RR_DBUS_ATTR_FROM, g_variant_new_string(self->from_str - ?: nm_utils_inet_ntop(_ip_routing_rule_get_addr_family(self), - &self->from_bin, - addr_str))); + ?: nm_inet_ntop(_ip_routing_rule_get_addr_family(self), + &self->from_bin, + addr_str))); _rr_to_dbus_add(&builder, RR_DBUS_ATTR_FROM_LEN, g_variant_new_byte(self->from_len)); } @@ -3231,9 +3229,9 @@ nm_ip_routing_rule_to_dbus(const NMIPRoutingRule *self) &builder, RR_DBUS_ATTR_TO, g_variant_new_string(self->to_str - ?: nm_utils_inet_ntop(_ip_routing_rule_get_addr_family(self), - &self->to_bin, - addr_str))); + ?: nm_inet_ntop(_ip_routing_rule_get_addr_family(self), + &self->to_bin, + addr_str))); _rr_to_dbus_add(&builder, RR_DBUS_ATTR_TO_LEN, g_variant_new_byte(self->to_len)); } @@ -3632,11 +3630,11 @@ next_words_consumed: } if (!NM_IN_STRSET(word_from, NULL, "all")) { - if (!nm_utils_parse_inaddr_prefix_bin(addr_family, - word_from, - &addr_family, - &val_from, - &val_from_len)) { + if (!nm_inet_parse_with_prefix_bin(addr_family, + word_from, + &addr_family, + &val_from, + &val_from_len)) { g_set_error_literal(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED, @@ -3648,11 +3646,11 @@ next_words_consumed: } if (!NM_IN_STRSET(word_to, NULL, "all")) { - if (!nm_utils_parse_inaddr_prefix_bin(addr_family, - word_to, - &addr_family, - &val_to, - &val_to_len)) { + if (!nm_inet_parse_with_prefix_bin(addr_family, + word_to, + &addr_family, + &val_to, + &val_to_len)) { g_set_error_literal(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED, @@ -3751,7 +3749,7 @@ _rr_string_append_inet_addr(NMStrBuf *str, const NMIPAddr *addr_bin, guint8 addr_len) { - char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + char addr_str[NM_INET_ADDRSTRLEN]; if (addr_len == 0) { if (required) { @@ -3766,7 +3764,7 @@ _rr_string_append_inet_addr(NMStrBuf *str, nm_str_buf_append_printf(nm_str_buf_append_required_delimiter(str, ' '), "%s %s", is_from ? "from" : "to", - nm_utils_inet_ntop(addr_family, addr_bin, addr_str)); + nm_inet_ntop(addr_family, addr_bin, addr_str)); if (addr_len != nm_utils_addr_family_to_size(addr_family) * 8) { nm_str_buf_append_printf(str, "/%u", addr_len); } @@ -4058,7 +4056,7 @@ nm_setting_ip_config_add_dns(NMSettingIPConfig *setting, const char *dns) NMSettingIPConfigPrivate *priv; int addr_family; NMIPAddr dns_bin; - char dns_canonical[NM_UTILS_INET_ADDRSTRLEN]; + char dns_canonical[NM_INET_ADDRSTRLEN]; guint i; g_return_val_if_fail(NM_IS_SETTING_IP_CONFIG(setting), FALSE); @@ -4067,13 +4065,13 @@ nm_setting_ip_config_add_dns(NMSettingIPConfig *setting, const char *dns) if (!valid_ip(addr_family, dns, &dns_bin, NULL)) { g_return_val_if_fail(dns != NULL, FALSE); - g_return_val_if_fail(nm_utils_ipaddr_is_valid(addr_family, dns), FALSE); + g_return_val_if_fail(nm_inet_is_valid(addr_family, dns), FALSE); nm_assert_not_reached(); } priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(setting); - nm_utils_inet_ntop(addr_family, &dns_bin, dns_canonical); + nm_inet_ntop(addr_family, &dns_bin, dns_canonical); for (i = 0; i < priv->dns->len; i++) { if (nm_streq(dns_canonical, priv->dns->pdata[i])) @@ -4121,7 +4119,7 @@ nm_setting_ip_config_remove_dns_by_value(NMSettingIPConfig *setting, const char NMSettingIPConfigPrivate *priv; int addr_family; NMIPAddr dns_bin; - char dns_canonical[NM_UTILS_INET_ADDRSTRLEN]; + char dns_canonical[NM_INET_ADDRSTRLEN]; guint i; g_return_val_if_fail(NM_IS_SETTING_IP_CONFIG(setting), FALSE); @@ -4130,13 +4128,13 @@ nm_setting_ip_config_remove_dns_by_value(NMSettingIPConfig *setting, const char if (!valid_ip(addr_family, dns, &dns_bin, NULL)) { g_return_val_if_fail(dns != NULL, FALSE); - g_return_val_if_fail(nm_utils_ipaddr_is_valid(addr_family, dns), FALSE); + g_return_val_if_fail(nm_inet_is_valid(addr_family, dns), FALSE); nm_assert_not_reached(); } priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(setting); - nm_utils_inet_ntop(addr_family, &dns_bin, dns_canonical); + nm_inet_ntop(addr_family, &dns_bin, dns_canonical); for (i = 0; i < priv->dns->len; i++) { if (nm_streq(dns_canonical, priv->dns->pdata[i])) { @@ -5441,7 +5439,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) for (i = 0; i < priv->dns->len; i++) { const char *dns = priv->dns->pdata[i]; - if (!nm_utils_ipaddr_is_valid(NM_SETTING_IP_CONFIG_GET_FAMILY(setting), dns)) { + if (!nm_inet_is_valid(NM_SETTING_IP_CONFIG_GET_FAMILY(setting), dns)) { g_set_error(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -5517,7 +5515,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } - if (!nm_utils_ipaddr_is_valid(NM_SETTING_IP_CONFIG_GET_FAMILY(setting), priv->gateway)) { + if (!nm_inet_is_valid(NM_SETTING_IP_CONFIG_GET_FAMILY(setting), priv->gateway)) { g_set_error_literal(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -5649,7 +5647,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } for (i = 0; i < priv->dhcp_reject_servers->len; i++) { - if (!nm_utils_parse_inaddr_prefix( + if (!nm_inet_parse_with_prefix_str( NM_SETTING_IP_CONFIG_GET_FAMILY(setting), g_array_index(priv->dhcp_reject_servers, const char *, i), NULL, diff --git a/src/libnm-core-impl/nm-setting-ip-tunnel.c b/src/libnm-core-impl/nm-setting-ip-tunnel.c index d42e97b9ae..935264b1d4 100644 --- a/src/libnm-core-impl/nm-setting-ip-tunnel.c +++ b/src/libnm-core-impl/nm-setting-ip-tunnel.c @@ -366,7 +366,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } - if (priv->local && !nm_utils_ipaddr_is_valid(family, priv->local)) { + if (priv->local && !nm_inet_is_valid(family, priv->local)) { g_set_error(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -392,7 +392,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } - if (!nm_utils_ipaddr_is_valid(family, priv->remote)) { + if (!nm_inet_is_valid(family, priv->remote)) { g_set_error(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, diff --git a/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index 8b593b9733..cad495150c 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -305,7 +305,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) if (priv->token) { if (priv->addr_gen_mode == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64) { struct in6_addr i6_token; - char s_token[NM_UTILS_INET_ADDRSTRLEN]; + char s_token[NM_INET_ADDRSTRLEN]; if (inet_pton(AF_INET6, priv->token, &i6_token) != 1 || !_nm_utils_inet6_is_token(&i6_token)) { @@ -320,7 +320,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } - if (g_strcmp0(priv->token, _nm_utils_inet6_ntop(&i6_token, s_token))) + if (g_strcmp0(priv->token, nm_inet6_ntop(&i6_token, s_token))) token_needs_normalization = TRUE; } else { g_set_error_literal(error, diff --git a/src/libnm-core-impl/nm-setting-vxlan.c b/src/libnm-core-impl/nm-setting-vxlan.c index f617a07357..3fb4c48d26 100644 --- a/src/libnm-core-impl/nm-setting-vxlan.c +++ b/src/libnm-core-impl/nm-setting-vxlan.c @@ -344,9 +344,9 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) gboolean remote_is_valid = TRUE; gboolean local_is_valid = TRUE; - if (priv->remote && !nm_utils_parse_inaddr_bin(addr_family, priv->remote, &addr_family, NULL)) + if (priv->remote && !nm_inet_parse_bin(addr_family, priv->remote, &addr_family, NULL)) remote_is_valid = FALSE; - if (priv->local && !nm_utils_parse_inaddr_bin(addr_family, priv->local, &addr_family, NULL)) + if (priv->local && !nm_inet_parse_bin(addr_family, priv->local, &addr_family, NULL)) local_is_valid = FALSE; if (!remote_is_valid) { diff --git a/src/libnm-core-impl/nm-setting-wireguard.c b/src/libnm-core-impl/nm-setting-wireguard.c index ad0f01d5c5..2cc1089eb2 100644 --- a/src/libnm-core-impl/nm-setting-wireguard.c +++ b/src/libnm-core-impl/nm-setting-wireguard.c @@ -628,18 +628,18 @@ _peer_append_allowed_ip(NMWireGuardPeer *self, const char *allowed_ip, gboolean /* normalize the address (if it is valid. Otherwise, take it * as-is (it will render the instance invalid). */ - if (!nm_utils_parse_inaddr_prefix_bin(AF_UNSPEC, allowed_ip, &addr_family, &addrbin, &prefix)) { + if (!nm_inet_parse_with_prefix_bin(AF_UNSPEC, allowed_ip, &addr_family, &addrbin, &prefix)) { if (!accept_invalid) return FALSE; /* mark the entry as invalid by having a "X" prefix. */ str = g_strconcat(ALLOWED_IP_INVALID_X_STR, allowed_ip, NULL); is_valid = FALSE; } else { - char addrstr[NM_UTILS_INET_ADDRSTRLEN]; + char addrstr[NM_INET_ADDRSTRLEN]; nm_assert_addr_family(addr_family); - nm_utils_inet_ntop(addr_family, &addrbin, addrstr); + nm_inet_ntop(addr_family, &addrbin, addrstr); if (prefix >= 0) str = g_strdup_printf("%s/%d", addrstr, prefix); else diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index 3c4cbc651e..b6e57de144 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -269,7 +269,7 @@ nm_sock_addr_endpoint_get_fixed_sockaddr(NMSockAddrEndpoint *self, gpointer sock if (!self->host) return FALSE; - if (nm_utils_parse_inaddr_bin(AF_UNSPEC, self->host, &addr_family, &addrbin)) + if (nm_inet_parse_bin(AF_UNSPEC, self->host, &addr_family, &addrbin)) goto good; /* See if there is an IPv6 scope-id... @@ -295,7 +295,7 @@ nm_sock_addr_endpoint_get_fixed_sockaddr(NMSockAddrEndpoint *self, gpointer sock const char *host_part; host_part = nm_strndup_a(200, self->host, s - self->host, &tmp_str); - if (nm_utils_parse_inaddr_bin(AF_INET6, host_part, &addr_family, &addrbin)) + if (nm_inet_parse_bin(AF_INET6, host_part, &addr_family, &addrbin)) goto good; } @@ -1346,7 +1346,7 @@ nm_utils_ip4_dns_from_variant(GVariant *value) array = g_variant_get_fixed_array(value, &length, sizeof(guint32)); dns = g_new(char *, length + 1u); for (i = 0; i < length; i++) - dns[i] = nm_utils_inet4_ntop_dup(array[i]); + dns[i] = nm_inet4_ntop_dup(array[i]); dns[i] = NULL; return dns; @@ -1449,7 +1449,7 @@ nm_utils_ip4_addresses_from_variant(GVariant *value, char **out_gateway) g_ptr_array_add(addresses, addr); if (addr_array[2] && out_gateway && !*out_gateway) - *out_gateway = nm_utils_inet4_ntop_dup(addr_array[2]); + *out_gateway = nm_inet4_ntop_dup(addr_array[2]); } else { g_warning("Ignoring invalid IP4 address: %s", error->message); g_clear_error(&error); @@ -1571,7 +1571,7 @@ nm_utils_ip4_routes_from_variant(GVariant *value) guint32 nm_utils_ip4_netmask_to_prefix(guint32 netmask) { - return _nm_utils_ip4_netmask_to_prefix(netmask); + return nm_ip4_addr_netmask_to_prefix(netmask); } /** @@ -1585,7 +1585,7 @@ nm_utils_ip4_prefix_to_netmask(guint32 prefix) { g_return_val_if_fail(prefix <= 32, 0xffffffffu); - return _nm_utils_ip4_prefix_to_netmask(prefix); + return nm_ip4_addr_netmask_from_prefix(prefix); } /** @@ -1603,7 +1603,7 @@ nm_utils_ip4_prefix_to_netmask(guint32 prefix) guint32 nm_utils_ip4_get_default_prefix(guint32 ip) { - return _nm_utils_ip4_get_default_prefix(ip); + return nm_ip4_addr_get_default_prefix(ip); } /** @@ -1676,7 +1676,7 @@ nm_utils_ip6_dns_from_variant(GVariant *value) const struct in6_addr *ip = g_variant_get_fixed_array(ip_var, &length, 1); if (length == sizeof(struct in6_addr)) - dns[i++] = nm_utils_inet6_ntop_dup(ip); + dns[i++] = nm_inet6_ntop_dup(ip); g_variant_unref(ip_var); } @@ -1798,7 +1798,7 @@ nm_utils_ip6_addresses_from_variant(GVariant *value, char **out_gateway) goto next; } if (!IN6_IS_ADDR_UNSPECIFIED(gateway_bytes)) - *out_gateway = nm_utils_inet6_ntop_dup(gateway_bytes); + *out_gateway = nm_inet6_ntop_dup(gateway_bytes); } } else { g_warning("Ignoring invalid IP6 address: %s", error->message); @@ -3825,13 +3825,13 @@ _nm_utils_ipaddr_canonical_or_invalid(int addr_family, const char *ip, gboolean if (!ip) return NULL; - if (!nm_utils_parse_inaddr_bin(addr_family, ip, &addr_family, &addr_bin)) + if (!nm_inet_parse_bin(addr_family, ip, &addr_family, &addr_bin)) return g_strdup(ip); if (map_zero_to_null && nm_ip_addr_is_null(addr_family, &addr_bin)) return NULL; - return nm_utils_inet_ntop_dup(addr_family, &addr_bin); + return nm_inet_ntop_dup(addr_family, &addr_bin); } /* @@ -4363,13 +4363,13 @@ nm_utils_is_uuid(const char *str) return nm_uuid_is_valid_nmlegacy(str); } -static _nm_thread_local char _nm_utils_inet_ntop_buffer[NM_UTILS_INET_ADDRSTRLEN]; +static _nm_thread_local char _nm_utils_inet_ntop_buffer[NM_INET_ADDRSTRLEN]; /** * nm_utils_inet4_ntop: (skip) * @inaddr: the address that should be converted to string. * @dst: the destination buffer, it must contain at least - * INET_ADDRSTRLEN or %NM_UTILS_INET_ADDRSTRLEN + * INET_ADDRSTRLEN or %NM_INET_ADDRSTRLEN * characters. If set to %NULL, it will return a pointer to an internal, static * buffer (shared with nm_utils_inet6_ntop()). Beware, that the internal * buffer will be overwritten with ever new call of nm_utils_inet4_ntop() or @@ -4391,14 +4391,14 @@ nm_utils_inet4_ntop(in_addr_t inaddr, char *dst) * * However, still support it to be lenient against mistakes and because * this is public API of libnm. */ - return _nm_utils_inet4_ntop(inaddr, dst ?: _nm_utils_inet_ntop_buffer); + return nm_inet4_ntop(inaddr, dst ?: _nm_utils_inet_ntop_buffer); } /** * nm_utils_inet6_ntop: (skip) * @in6addr: the address that should be converted to string. * @dst: the destination buffer, it must contain at least - * INET6_ADDRSTRLEN or %NM_UTILS_INET_ADDRSTRLEN + * INET6_ADDRSTRLEN or %NM_INET_ADDRSTRLEN * characters. If set to %NULL, it will return a pointer to an internal, static * buffer (shared with nm_utils_inet4_ntop()). Beware, that the internal * buffer will be overwritten with ever new call of nm_utils_inet4_ntop() or @@ -4422,7 +4422,7 @@ nm_utils_inet6_ntop(const struct in6_addr *in6addr, char *dst) * However, still support it to be lenient against mistakes and because * this is public API of libnm. */ g_return_val_if_fail(in6addr, NULL); - return _nm_utils_inet6_ntop(in6addr, dst ?: _nm_utils_inet_ntop_buffer); + return nm_inet6_ntop(in6addr, dst ?: _nm_utils_inet_ntop_buffer); } /** @@ -4440,7 +4440,7 @@ nm_utils_ipaddr_valid(int family, const char *ip) { g_return_val_if_fail(family == AF_INET || family == AF_INET6 || family == AF_UNSPEC, FALSE); - return nm_utils_ipaddr_is_valid(family, ip); + return nm_inet_is_valid(family, ip); } /** diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c index 3c8cd3bab2..19d3271944 100644 --- a/src/libnm-core-impl/tests/test-general.c +++ b/src/libnm-core-impl/tests/test-general.c @@ -5058,7 +5058,7 @@ _netmask_to_prefix(guint32 netmask) /* we re-implemented the netmask-to-prefix code differently. Check * that they agree. */ - g_assert_cmpint(prefix, ==, _nm_utils_ip4_netmask_to_prefix(netmask)); + g_assert_cmpint(prefix, ==, nm_ip4_addr_netmask_to_prefix(netmask)); return prefix; } @@ -5069,7 +5069,7 @@ test_ip4_prefix_to_netmask(void) int i; for (i = 0; i <= 32; i++) { - guint32 netmask = _nm_utils_ip4_prefix_to_netmask(i); + guint32 netmask = nm_ip4_addr_netmask_from_prefix(i); int plen = _netmask_to_prefix(netmask); g_assert_cmpint(i, ==, plen); @@ -5097,8 +5097,8 @@ test_ip4_netmask_to_prefix(void) g_rand_set_seed(rand, 1); for (i = 2; i <= 32; i++) { - guint32 netmask = _nm_utils_ip4_prefix_to_netmask(i); - guint32 netmask_lowest_bit = netmask & ~_nm_utils_ip4_prefix_to_netmask(i - 1); + guint32 netmask = nm_ip4_addr_netmask_from_prefix(i); + guint32 netmask_lowest_bit = netmask & ~nm_ip4_addr_netmask_from_prefix(i - 1); g_assert_cmpint(i, ==, _netmask_to_prefix(netmask)); @@ -7140,7 +7140,7 @@ _sock_addr_endpoint_fixed(const char *endpoint, const char *host, guint16 port, g_assert(host); g_assert(port > 0); - if (!nm_utils_parse_inaddr_bin(AF_UNSPEC, host, &addr_family, &addrbin)) + if (!nm_inet_parse_bin(AF_UNSPEC, host, &addr_family, &addrbin)) g_assert_not_reached(); ep = nm_sock_addr_endpoint_new(endpoint); @@ -10247,7 +10247,7 @@ test_nm_ip_addr_zero(void) { in_addr_t a4 = nmtst_inet4_from_string("0.0.0.0"); struct in6_addr a6 = *nmtst_inet6_from_string("::"); - char buf[NM_UTILS_INET_ADDRSTRLEN]; + char buf[NM_INET_ADDRSTRLEN]; NMIPAddr a = NM_IP_ADDR_INIT; g_assert(memcmp(&a, &nm_ip_addr_zero, sizeof(a)) == 0); @@ -10258,11 +10258,11 @@ test_nm_ip_addr_zero(void) g_assert(memcmp(&nm_ip_addr_zero, &a4, sizeof(a4)) == 0); g_assert(memcmp(&nm_ip_addr_zero, &a6, sizeof(a6)) == 0); - g_assert_cmpstr(_nm_utils_inet4_ntop(nm_ip_addr_zero.addr4, buf), ==, "0.0.0.0"); - g_assert_cmpstr(_nm_utils_inet6_ntop(&nm_ip_addr_zero.addr6, buf), ==, "::"); + g_assert_cmpstr(nm_inet4_ntop(nm_ip_addr_zero.addr4, buf), ==, "0.0.0.0"); + g_assert_cmpstr(nm_inet6_ntop(&nm_ip_addr_zero.addr6, buf), ==, "::"); - g_assert_cmpstr(nm_utils_inet_ntop(AF_INET, &nm_ip_addr_zero, buf), ==, "0.0.0.0"); - g_assert_cmpstr(nm_utils_inet_ntop(AF_INET6, &nm_ip_addr_zero, buf), ==, "::"); + g_assert_cmpstr(nm_inet_ntop(AF_INET, &nm_ip_addr_zero, buf), ==, "0.0.0.0"); + g_assert_cmpstr(nm_inet_ntop(AF_INET6, &nm_ip_addr_zero, buf), ==, "::"); G_STATIC_ASSERT_EXPR(sizeof(a) == sizeof(a.array)); } diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 5bdae71660..6306437118 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -3755,7 +3755,7 @@ test_roundtrip_conversion(gconstpointer test_data) for (is_ipv4 = 0; is_ipv4 < 2; is_ipv4++) { g_assert(NM_IS_SETTING_IP_CONFIG(s_ip.s_x[is_ipv4])); for (i = 0; i < 3; i++) { - char addrstr[NM_UTILS_INET_ADDRSTRLEN]; + char addrstr[NM_INET_ADDRSTRLEN]; nm_auto_unref_ip_routing_rule NMIPRoutingRule *rr = NULL; diff --git a/src/libnm-core-public/nm-utils.h b/src/libnm-core-public/nm-utils.h index 5faed75a36..0a2aab1e4a 100644 --- a/src/libnm-core-public/nm-utils.h +++ b/src/libnm-core-public/nm-utils.h @@ -171,12 +171,12 @@ gboolean nm_utils_is_valid_iface_name(const char *name, GError **error); gboolean nm_utils_is_uuid(const char *str); /** - * NM_UTILS_INET_ADDRSTRLEN: + * NM_INET_ADDRSTRLEN: * * Defines the minimal length for a char buffer that is suitable as @dst argument * for both nm_utils_inet4_ntop() and nm_utils_inet6_ntop(). **/ -#define NM_UTILS_INET_ADDRSTRLEN INET6_ADDRSTRLEN +#define NM_INET_ADDRSTRLEN INET6_ADDRSTRLEN const char *nm_utils_inet4_ntop(guint32 inaddr, char *dst); diff --git a/src/libnm-glib-aux/nm-inet-utils.c b/src/libnm-glib-aux/nm-inet-utils.c index 46fd07ddb5..f8b287d086 100644 --- a/src/libnm-glib-aux/nm-inet-utils.c +++ b/src/libnm-glib-aux/nm-inet-utils.c @@ -115,7 +115,7 @@ nm_ip_addr_set_from_variant(int addr_family, gpointer dst, GVariant *variant, in /*****************************************************************************/ guint32 -_nm_utils_ip4_get_default_prefix0(in_addr_t ip) +nm_ip4_addr_get_default_prefix0(in_addr_t ip) { /* The function is originally from ipcalc.c of Red Hat's initscripts. */ switch (ntohl(ip) >> 24) { @@ -130,13 +130,13 @@ _nm_utils_ip4_get_default_prefix0(in_addr_t ip) } guint32 -_nm_utils_ip4_get_default_prefix(in_addr_t ip) +nm_ip4_addr_get_default_prefix(in_addr_t ip) { - return _nm_utils_ip4_get_default_prefix0(ip) ?: 24; + return nm_ip4_addr_get_default_prefix0(ip) ?: 24; } gboolean -nm_utils_ip_is_site_local(int addr_family, const void *address) +nm_ip_addr_is_site_local(int addr_family, const void *address) { in_addr_t addr4; @@ -158,7 +158,7 @@ nm_utils_ip_is_site_local(int addr_family, const void *address) } gboolean -nm_utils_ip6_is_ula(const struct in6_addr *address) +nm_ip6_addr_is_ula(const struct in6_addr *address) { /* Unique local IPv6 address (ULA) fc00::/7 */ return (address->s6_addr32[0] & htonl(0xfe000000u)) == htonl(0xfc000000u); @@ -167,7 +167,7 @@ nm_utils_ip6_is_ula(const struct in6_addr *address) /*****************************************************************************/ gconstpointer -nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint32 plen) +nm_ip_addr_clear_host_address(int family, gpointer dst, gconstpointer src, guint32 plen) { g_return_val_if_fail(dst, NULL); @@ -180,10 +180,10 @@ nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src = dst; } - *((guint32 *) dst) = nm_utils_ip4_address_clear_host_address(*((guint32 *) src), plen); + *((guint32 *) dst) = nm_ip4_addr_clear_host_address(*((guint32 *) src), plen); break; case AF_INET6: - nm_utils_ip6_address_clear_host_address(dst, src, plen); + nm_ip6_addr_clear_host_address(dst, src, plen); break; default: g_return_val_if_reached(NULL); @@ -191,7 +191,7 @@ nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer return dst; } -/* nm_utils_ip6_address_clear_host_address: +/* nm_ip6_addr_clear_host_address: * @dst: destination output buffer, will contain the network part of the @src address * @src: source ip6 address. If NULL, this does an in-place update of @dst. * Also, @src and @dst are allowed to be the same pointers. @@ -201,9 +201,7 @@ nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer * @dst and @src to the same destination or set @src NULL. */ const struct in6_addr * -nm_utils_ip6_address_clear_host_address(struct in6_addr *dst, - const struct in6_addr *src, - guint32 plen) +nm_ip6_addr_clear_host_address(struct in6_addr *dst, const struct in6_addr *src, guint32 plen) { g_return_val_if_fail(plen <= 128, NULL); g_return_val_if_fail(dst, NULL); @@ -230,9 +228,9 @@ nm_utils_ip6_address_clear_host_address(struct in6_addr *dst, } int -nm_utils_ip6_address_same_prefix_cmp(const struct in6_addr *addr_a, - const struct in6_addr *addr_b, - guint32 plen) +nm_ip6_addr_same_prefix_cmp(const struct in6_addr *addr_a, + const struct in6_addr *addr_b, + guint32 plen) { int nbytes; guint8 va, vb, m; @@ -360,11 +358,11 @@ _parse_legacy_addr4(const char *text, in_addr_t *out_addr, GError **error) } gboolean -nm_utils_parse_inaddr_bin_full(int addr_family, - gboolean accept_legacy, - const char *text, - int *out_addr_family, - gpointer out_addr) +nm_inet_parse_bin_full(int addr_family, + gboolean accept_legacy, + const char *text, + int *out_addr_family, + gpointer out_addr) { NMIPAddr addrbin; @@ -399,7 +397,7 @@ nm_utils_parse_inaddr_bin_full(int addr_family, g_error("unexpected assertion failure: could parse \"%s\" as %s, but not accepted by " "legacy parser: %s", text, - _nm_utils_inet4_ntop(addrbin.addr4, buf), + nm_inet4_ntop(addrbin.addr4, buf), error->message); } nm_assert(addrbin.addr4 == a); @@ -414,7 +412,7 @@ nm_utils_parse_inaddr_bin_full(int addr_family, } gboolean -nm_utils_parse_inaddr(int addr_family, const char *text, char **out_addr) +nm_inet_parse_str(int addr_family, const char *text, char **out_addr) { NMIPAddr addrbin; char addrstr_buf[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)]; @@ -435,11 +433,11 @@ nm_utils_parse_inaddr(int addr_family, const char *text, char **out_addr) } gboolean -nm_utils_parse_inaddr_prefix_bin(int addr_family, - const char *text, - int *out_addr_family, - gpointer out_addr, - int *out_prefix) +nm_inet_parse_with_prefix_bin(int addr_family, + const char *text, + int *out_addr_family, + gpointer out_addr, + int *out_prefix) { gs_free char *addrstr_free = NULL; int prefix = -1; @@ -481,12 +479,12 @@ nm_utils_parse_inaddr_prefix_bin(int addr_family, } gboolean -nm_utils_parse_inaddr_prefix(int addr_family, const char *text, char **out_addr, int *out_prefix) +nm_inet_parse_with_prefix_str(int addr_family, const char *text, char **out_addr, int *out_prefix) { NMIPAddr addrbin; char addrstr_buf[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)]; - if (!nm_utils_parse_inaddr_prefix_bin(addr_family, text, &addr_family, &addrbin, out_prefix)) + if (!nm_inet_parse_with_prefix_bin(addr_family, text, &addr_family, &addrbin, out_prefix)) return FALSE; NM_SET_OUT(out_addr, g_strdup(inet_ntop(addr_family, &addrbin, addrstr_buf, sizeof(addrstr_buf)))); @@ -496,28 +494,28 @@ nm_utils_parse_inaddr_prefix(int addr_family, const char *text, char **out_addr, /*****************************************************************************/ gboolean -nm_utils_ipaddr_is_valid(int addr_family, const char *str_addr) +nm_inet_is_valid(int addr_family, const char *str_addr) { nm_assert(NM_IN_SET(addr_family, AF_UNSPEC, AF_INET, AF_INET6)); - return str_addr && nm_utils_parse_inaddr_bin(addr_family, str_addr, NULL, NULL); + return str_addr && nm_inet_parse_bin(addr_family, str_addr, NULL, NULL); } gboolean -nm_utils_ipaddr_is_normalized(int addr_family, const char *str_addr) +nm_inet_is_normalized(int addr_family, const char *str_addr) { NMIPAddr addr; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; nm_assert(NM_IN_SET(addr_family, AF_UNSPEC, AF_INET, AF_INET6)); if (!str_addr) return FALSE; - if (!nm_utils_parse_inaddr_bin(addr_family, str_addr, &addr_family, &addr)) + if (!nm_inet_parse_bin(addr_family, str_addr, &addr_family, &addr)) return FALSE; - nm_utils_inet_ntop(addr_family, &addr, sbuf); + nm_inet_ntop(addr_family, &addr, sbuf); return nm_streq(sbuf, str_addr); } diff --git a/src/libnm-glib-aux/nm-inet-utils.h b/src/libnm-glib-aux/nm-inet-utils.h index ffb7f4ab0a..6530f4222f 100644 --- a/src/libnm-glib-aux/nm-inet-utils.h +++ b/src/libnm-glib-aux/nm-inet-utils.h @@ -128,7 +128,7 @@ nm_ip_addr_from_packed_array(int addr_family, gconstpointer ipaddr_arr, gsize id /*****************************************************************************/ static inline guint32 -_nm_utils_ip4_netmask_to_prefix(in_addr_t subnetmask) +nm_ip4_addr_netmask_to_prefix(in_addr_t subnetmask) { G_STATIC_ASSERT_EXPR(__SIZEOF_INT__ == 4); G_STATIC_ASSERT_EXPR(sizeof(int) == 4); @@ -139,104 +139,95 @@ _nm_utils_ip4_netmask_to_prefix(in_addr_t subnetmask) } /** - * _nm_utils_ip4_prefix_to_netmask: + * nm_ip4_addr_netmask_from_prefix: * @prefix: a CIDR prefix * * Returns: the netmask represented by the prefix, in network byte order **/ static inline in_addr_t -_nm_utils_ip4_prefix_to_netmask(guint32 prefix) +nm_ip4_addr_netmask_from_prefix(guint32 prefix) { nm_assert(prefix <= 32); return prefix < 32 ? ~htonl(0xFFFFFFFFu >> prefix) : 0xFFFFFFFFu; } -guint32 _nm_utils_ip4_get_default_prefix0(in_addr_t ip); -guint32 _nm_utils_ip4_get_default_prefix(in_addr_t ip); +guint32 nm_ip4_addr_get_default_prefix0(in_addr_t ip); +guint32 nm_ip4_addr_get_default_prefix(in_addr_t ip); gconstpointer -nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint32 plen); +nm_ip_addr_clear_host_address(int family, gpointer dst, gconstpointer src, guint32 plen); -/* nm_utils_ip4_address_clear_host_address: +/* nm_ip4_addr_clear_host_address: * @addr: source ip6 address * @plen: prefix length of network * * returns: the input address, with the host address set to 0. */ static inline in_addr_t -nm_utils_ip4_address_clear_host_address(in_addr_t addr, guint32 plen) +nm_ip4_addr_clear_host_address(in_addr_t addr, guint32 plen) { - return addr & _nm_utils_ip4_prefix_to_netmask(plen); + return addr & nm_ip4_addr_netmask_from_prefix(plen); } -const struct in6_addr *nm_utils_ip6_address_clear_host_address(struct in6_addr *dst, - const struct in6_addr *src, - guint32 plen); +const struct in6_addr * +nm_ip6_addr_clear_host_address(struct in6_addr *dst, const struct in6_addr *src, guint32 plen); /*****************************************************************************/ static inline int -nm_utils_ip4_address_same_prefix_cmp(in_addr_t addr_a, in_addr_t addr_b, guint32 plen) +nm_ip4_addr_same_prefix_cmp(in_addr_t addr_a, in_addr_t addr_b, guint32 plen) { - NM_CMP_DIRECT(htonl(nm_utils_ip4_address_clear_host_address(addr_a, plen)), - htonl(nm_utils_ip4_address_clear_host_address(addr_b, plen))); + NM_CMP_DIRECT(htonl(nm_ip4_addr_clear_host_address(addr_a, plen)), + htonl(nm_ip4_addr_clear_host_address(addr_b, plen))); return 0; } -int nm_utils_ip6_address_same_prefix_cmp(const struct in6_addr *addr_a, - const struct in6_addr *addr_b, - guint32 plen); +int nm_ip6_addr_same_prefix_cmp(const struct in6_addr *addr_a, + const struct in6_addr *addr_b, + guint32 plen); static inline gboolean -nm_utils_ip4_address_same_prefix(in_addr_t addr_a, in_addr_t addr_b, guint32 plen) +nm_ip4_addr_same_prefix(in_addr_t addr_a, in_addr_t addr_b, guint32 plen) { - return nm_utils_ip4_address_same_prefix_cmp(addr_a, addr_b, plen) == 0; + return nm_ip4_addr_same_prefix_cmp(addr_a, addr_b, plen) == 0; } static inline gboolean -nm_utils_ip6_address_same_prefix(const struct in6_addr *addr_a, - const struct in6_addr *addr_b, - guint8 plen) +nm_ip6_addr_same_prefix(const struct in6_addr *addr_a, const struct in6_addr *addr_b, guint8 plen) { - return nm_utils_ip6_address_same_prefix_cmp(addr_a, addr_b, plen) == 0; + return nm_ip6_addr_same_prefix_cmp(addr_a, addr_b, plen) == 0; } static inline int -nm_utils_ip_address_same_prefix_cmp(int addr_family, - gconstpointer addr_a, - gconstpointer addr_b, - guint8 plen) +nm_ip_addr_same_prefix_cmp(int addr_family, gconstpointer addr_a, gconstpointer addr_b, guint8 plen) { NM_CMP_SELF(addr_a, addr_b); if (NM_IS_IPv4(addr_family)) { - return nm_utils_ip4_address_same_prefix_cmp(*((const in_addr_t *) addr_a), - *((const in_addr_t *) addr_b), - plen); + return nm_ip4_addr_same_prefix_cmp(*((const in_addr_t *) addr_a), + *((const in_addr_t *) addr_b), + plen); } - return nm_utils_ip6_address_same_prefix_cmp(addr_a, addr_b, plen); + return nm_ip6_addr_same_prefix_cmp(addr_a, addr_b, plen); } static inline gboolean -nm_utils_ip_address_same_prefix(int addr_family, - gconstpointer addr_a, - gconstpointer addr_b, - guint8 plen) +nm_ip_addr_same_prefix(int addr_family, gconstpointer addr_a, gconstpointer addr_b, guint8 plen) { - return nm_utils_ip_address_same_prefix_cmp(addr_family, addr_a, addr_b, plen) == 0; + return nm_ip_addr_same_prefix_cmp(addr_family, addr_a, addr_b, plen) == 0; } -#define NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX(a, b, plen) \ - NM_CMP_RETURN(nm_utils_ip4_address_same_prefix_cmp((a), (b), (plen))) +#define NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX(a, b, plen) \ + NM_CMP_RETURN(nm_ip4_addr_same_prefix_cmp((a), (b), (plen))) -#define NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX(a, b, plen) \ - NM_CMP_RETURN(nm_utils_ip6_address_same_prefix_cmp((a), (b), (plen))) +#define NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX(a, b, plen) \ + NM_CMP_RETURN(nm_ip6_addr_same_prefix_cmp((a), (b), (plen))) /*****************************************************************************/ -gboolean nm_utils_ip_is_site_local(int addr_family, const void *address); -gboolean nm_utils_ip6_is_ula(const struct in6_addr *address); +gboolean nm_ip_addr_is_site_local(int addr_family, const void *address); +gboolean nm_ip6_addr_is_ula(const struct in6_addr *address); /*****************************************************************************/ @@ -244,7 +235,7 @@ gboolean nm_utils_ip6_is_ula(const struct in6_addr *address); #define NM_IPV4LL_NETMASK ((in_addr_t) htonl(0xFFFF0000lu)) static inline gboolean -nm_utils_ip4_address_is_loopback(in_addr_t addr) +nm_ip4_addr_is_loopback(in_addr_t addr) { /* There is also IN_LOOPBACK() in , but there the * argument is in host order not `in_addr_t`. */ @@ -252,13 +243,13 @@ nm_utils_ip4_address_is_loopback(in_addr_t addr) } static inline gboolean -nm_utils_ip4_address_is_link_local(in_addr_t addr) +nm_ip4_addr_is_link_local(in_addr_t addr) { return (addr & NM_IPV4LL_NETMASK) == NM_IPV4LL_NETWORK; } static inline gboolean -nm_utils_ip4_address_is_zeronet(in_addr_t network) +nm_ip4_addr_is_zeronet(in_addr_t network) { /* Same as ipv4_is_zeronet() from kernel's include/linux/in.h. */ return (network & htonl(0xFF000000u)) == htonl(0x00000000u); @@ -266,13 +257,13 @@ nm_utils_ip4_address_is_zeronet(in_addr_t network) /*****************************************************************************/ -#define NM_UTILS_INET_ADDRSTRLEN INET6_ADDRSTRLEN +#define NM_INET_ADDRSTRLEN INET6_ADDRSTRLEN /* Forward declare function so we don't have to drag in . */ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); static inline const char * -nm_utils_inet_ntop(int addr_family, gconstpointer addr, char *dst) +nm_inet_ntop(int addr_family, gconstpointer addr, char *dst) { const char *s; @@ -289,69 +280,66 @@ nm_utils_inet_ntop(int addr_family, gconstpointer addr, char *dst) } static inline const char * -_nm_utils_inet4_ntop(in_addr_t addr, char dst[static INET_ADDRSTRLEN]) +nm_inet4_ntop(in_addr_t addr, char dst[static INET_ADDRSTRLEN]) { - return nm_utils_inet_ntop(AF_INET, &addr, dst); + return nm_inet_ntop(AF_INET, &addr, dst); } static inline const char * -_nm_utils_inet6_ntop(const struct in6_addr *addr, char dst[static INET6_ADDRSTRLEN]) +nm_inet6_ntop(const struct in6_addr *addr, char dst[static INET6_ADDRSTRLEN]) { - return nm_utils_inet_ntop(AF_INET6, addr, dst); + return nm_inet_ntop(AF_INET6, addr, dst); } static inline char * -nm_utils_inet_ntop_dup(int addr_family, gconstpointer addr) +nm_inet_ntop_dup(int addr_family, gconstpointer addr) { - char buf[NM_UTILS_INET_ADDRSTRLEN]; + char buf[NM_INET_ADDRSTRLEN]; - return g_strdup(nm_utils_inet_ntop(addr_family, addr, buf)); + return g_strdup(nm_inet_ntop(addr_family, addr, buf)); } static inline char * -nm_utils_inet4_ntop_dup(in_addr_t addr) +nm_inet4_ntop_dup(in_addr_t addr) { - return nm_utils_inet_ntop_dup(AF_INET, &addr); + return nm_inet_ntop_dup(AF_INET, &addr); } static inline char * -nm_utils_inet6_ntop_dup(const struct in6_addr *addr) +nm_inet6_ntop_dup(const struct in6_addr *addr) { - return nm_utils_inet_ntop_dup(AF_INET6, addr); + return nm_inet_ntop_dup(AF_INET6, addr); } /*****************************************************************************/ -gboolean nm_utils_parse_inaddr_bin_full(int addr_family, - gboolean accept_legacy, - const char *text, - int *out_addr_family, - gpointer out_addr); +gboolean nm_inet_parse_bin_full(int addr_family, + gboolean accept_legacy, + const char *text, + int *out_addr_family, + gpointer out_addr); static inline gboolean -nm_utils_parse_inaddr_bin(int addr_family, - const char *text, - int *out_addr_family, - gpointer out_addr) +nm_inet_parse_bin(int addr_family, const char *text, int *out_addr_family, gpointer out_addr) { - return nm_utils_parse_inaddr_bin_full(addr_family, FALSE, text, out_addr_family, out_addr); + return nm_inet_parse_bin_full(addr_family, FALSE, text, out_addr_family, out_addr); } -gboolean nm_utils_parse_inaddr(int addr_family, const char *text, char **out_addr); +gboolean nm_inet_parse_str(int addr_family, const char *text, char **out_addr); -gboolean nm_utils_parse_inaddr_prefix_bin(int addr_family, - const char *text, - int *out_addr_family, - gpointer out_addr, - int *out_prefix); +gboolean nm_inet_parse_with_prefix_bin(int addr_family, + const char *text, + int *out_addr_family, + gpointer out_addr, + int *out_prefix); gboolean -nm_utils_parse_inaddr_prefix(int addr_family, const char *text, char **out_addr, int *out_prefix); +nm_inet_parse_with_prefix_str(int addr_family, const char *text, char **out_addr, int *out_prefix); /*****************************************************************************/ -gboolean nm_utils_ipaddr_is_valid(int addr_family, const char *str_addr); +gboolean nm_inet_is_valid(int addr_family, const char *str_addr); -gboolean nm_utils_ipaddr_is_normalized(int addr_family, const char *str_addr); +gboolean nm_inet_is_normalized(int addr_family, const char *str_addr); /*****************************************************************************/ diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c index 057fc0f389..524f0c31b1 100644 --- a/src/libnm-glib-aux/nm-shared-utils.c +++ b/src/libnm-glib-aux/nm-shared-utils.c @@ -139,7 +139,7 @@ nm_utils_ipv6_interface_identifier_get_from_token(NMUtilsIPv6IfaceId *iid, const /** * nm_utils_inet6_interface_identifier_to_token: * @iid: %NMUtilsIPv6IfaceId interface identifier - * @buf: the destination buffer of at least %NM_UTILS_INET_ADDRSTRLEN + * @buf: the destination buffer of at least %NM_INET_ADDRSTRLEN * bytes. * * Converts the interface identifier to a string token. @@ -156,7 +156,7 @@ nm_utils_inet6_interface_identifier_to_token(const NMUtilsIPv6IfaceId *iid, nm_assert(buf); nm_utils_ipv6_addr_set_interface_identifier(&i6_token, iid); - return _nm_utils_inet6_ntop(&i6_token, buf); + return nm_inet6_ntop(&i6_token, buf); } /*****************************************************************************/ diff --git a/src/libnm-glib-aux/nm-test-utils.h b/src/libnm-glib-aux/nm-test-utils.h index 83702070b8..fd2ddf86fb 100644 --- a/src/libnm-glib-aux/nm-test-utils.h +++ b/src/libnm-glib-aux/nm-test-utils.h @@ -1944,9 +1944,9 @@ nmtst_setting_ip_config_add_address(NMSettingIPConfig *s_ip, const char *address g_assert(s_ip); - if (nm_utils_ipaddr_is_valid(AF_INET, address)) + if (nm_inet_is_valid(AF_INET, address)) family = AF_INET; - else if (nm_utils_ipaddr_is_valid(AF_INET6, address)) + else if (nm_inet_is_valid(AF_INET6, address)) family = AF_INET6; else g_assert_not_reached(); @@ -1969,9 +1969,9 @@ nmtst_setting_ip_config_add_route(NMSettingIPConfig *s_ip, g_assert(s_ip); - if (nm_utils_ipaddr_is_valid(AF_INET, dest)) + if (nm_inet_is_valid(AF_INET, dest)) family = AF_INET; - else if (nm_utils_ipaddr_is_valid(AF_INET6, dest)) + else if (nm_inet_is_valid(AF_INET6, dest)) family = AF_INET6; else g_assert_not_reached(); @@ -2913,7 +2913,7 @@ nmtst_ip_address_new(int addr_family, const char *str) GError *error = NULL; NMIPAddress *a; - if (!nm_utils_parse_inaddr_prefix_bin(addr_family, str, &addr_family, &addr, &plen)) + if (!nm_inet_parse_with_prefix_bin(addr_family, str, &addr_family, &addr, &plen)) g_assert_not_reached(); if (plen == -1) diff --git a/src/libnm-glib-aux/tests/test-shared-general.c b/src/libnm-glib-aux/tests/test-shared-general.c index 7d36d64a8c..ef5a645868 100644 --- a/src/libnm-glib-aux/tests/test-shared-general.c +++ b/src/libnm-glib-aux/tests/test-shared-general.c @@ -253,12 +253,12 @@ test_nm_strndup_a(void) static void test_nm_utils_ip4_address_is_loopback(void) { - g_assert(nm_utils_ip4_address_is_loopback(nmtst_inet4_from_string("127.0.0.0"))); - g_assert(nm_utils_ip4_address_is_loopback(nmtst_inet4_from_string("127.0.0.1"))); - g_assert(nm_utils_ip4_address_is_loopback(nmtst_inet4_from_string("127.5.0.1"))); - g_assert(!nm_utils_ip4_address_is_loopback(nmtst_inet4_from_string("126.5.0.1"))); - g_assert(!nm_utils_ip4_address_is_loopback(nmtst_inet4_from_string("128.5.0.1"))); - g_assert(!nm_utils_ip4_address_is_loopback(nmtst_inet4_from_string("129.5.0.1"))); + g_assert(nm_ip4_addr_is_loopback(nmtst_inet4_from_string("127.0.0.0"))); + g_assert(nm_ip4_addr_is_loopback(nmtst_inet4_from_string("127.0.0.1"))); + g_assert(nm_ip4_addr_is_loopback(nmtst_inet4_from_string("127.5.0.1"))); + g_assert(!nm_ip4_addr_is_loopback(nmtst_inet4_from_string("126.5.0.1"))); + g_assert(!nm_ip4_addr_is_loopback(nmtst_inet4_from_string("128.5.0.1"))); + g_assert(!nm_ip4_addr_is_loopback(nmtst_inet4_from_string("129.5.0.1"))); } /*****************************************************************************/ @@ -266,22 +266,22 @@ test_nm_utils_ip4_address_is_loopback(void) static void test_nm_utils_ip4_prefix_to_netmask(void) { - g_assert_cmpint(_nm_utils_ip4_prefix_to_netmask(0), ==, nmtst_inet4_from_string("0.0.0.0")); - g_assert_cmpint(_nm_utils_ip4_prefix_to_netmask(1), ==, nmtst_inet4_from_string("128.0.0.0")); - g_assert_cmpint(_nm_utils_ip4_prefix_to_netmask(2), ==, nmtst_inet4_from_string("192.0.0.0")); - g_assert_cmpint(_nm_utils_ip4_prefix_to_netmask(16), + g_assert_cmpint(nm_ip4_addr_netmask_from_prefix(0), ==, nmtst_inet4_from_string("0.0.0.0")); + g_assert_cmpint(nm_ip4_addr_netmask_from_prefix(1), ==, nmtst_inet4_from_string("128.0.0.0")); + g_assert_cmpint(nm_ip4_addr_netmask_from_prefix(2), ==, nmtst_inet4_from_string("192.0.0.0")); + g_assert_cmpint(nm_ip4_addr_netmask_from_prefix(16), ==, nmtst_inet4_from_string("255.255.0.0")); - g_assert_cmpint(_nm_utils_ip4_prefix_to_netmask(24), + g_assert_cmpint(nm_ip4_addr_netmask_from_prefix(24), ==, nmtst_inet4_from_string("255.255.255.0")); - g_assert_cmpint(_nm_utils_ip4_prefix_to_netmask(30), + g_assert_cmpint(nm_ip4_addr_netmask_from_prefix(30), ==, nmtst_inet4_from_string("255.255.255.252")); - g_assert_cmpint(_nm_utils_ip4_prefix_to_netmask(31), + g_assert_cmpint(nm_ip4_addr_netmask_from_prefix(31), ==, nmtst_inet4_from_string("255.255.255.254")); - g_assert_cmpint(_nm_utils_ip4_prefix_to_netmask(32), + g_assert_cmpint(nm_ip4_addr_netmask_from_prefix(32), ==, nmtst_inet4_from_string("255.255.255.255")); } diff --git a/src/libnm-platform/nm-linux-platform.c b/src/libnm-platform/nm-linux-platform.c index cd685fe20e..472884d3d5 100644 --- a/src/libnm-platform/nm-linux-platform.c +++ b/src/libnm-platform/nm-linux-platform.c @@ -8122,7 +8122,7 @@ static gboolean link_set_token(NMPlatform *platform, int ifindex, const NMUtilsIPv6IfaceId *iid) { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; _LOGD("link: change %d: token: set IPv6 address generation token to %s", ifindex, diff --git a/src/libnm-platform/nm-platform.c b/src/libnm-platform/nm-platform.c index df177485ff..c023506439 100644 --- a/src/libnm-platform/nm-platform.c +++ b/src/libnm-platform/nm-platform.c @@ -3588,7 +3588,7 @@ nm_platform_ip_address_match(int addr_family, nm_assert(NM_FLAGS_ANY(match_flag, NM_PLATFORM_MATCH_WITH_ADDRSTATE__ANY)); if (addr_family == AF_INET) { - if (nm_utils_ip4_address_is_link_local(((NMPlatformIP4Address *) address)->address)) { + if (nm_ip4_addr_is_link_local(((NMPlatformIP4Address *) address)->address)) { if (!NM_FLAGS_HAS(match_flag, NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL)) return FALSE; } else { @@ -3723,8 +3723,8 @@ nm_platform_ip4_address_delete(NMPlatform *self, in_addr_t peer_address) { char str_dev[TO_STRING_DEV_BUF_SIZE]; - char b1[NM_UTILS_INET_ADDRSTRLEN]; - char b2[NM_UTILS_INET_ADDRSTRLEN]; + char b1[NM_INET_ADDRSTRLEN]; + char b2[NM_INET_ADDRSTRLEN]; char str_peer[INET_ADDRSTRLEN + 50]; _CHECK_SELF(self, klass, FALSE); @@ -3733,10 +3733,10 @@ nm_platform_ip4_address_delete(NMPlatform *self, g_return_val_if_fail(plen <= 32, FALSE); _LOG3D("address: deleting IPv4 address %s/%d, %s%s", - _nm_utils_inet4_ntop(address, b1), + nm_inet4_ntop(address, b1), plen, peer_address != address - ? nm_sprintf_buf(str_peer, "peer %s, ", _nm_utils_inet4_ntop(peer_address, b2)) + ? nm_sprintf_buf(str_peer, "peer %s, ", nm_inet4_ntop(peer_address, b2)) : "", _to_string_dev(self, ifindex, str_dev, sizeof(str_dev))); return klass->ip4_address_delete(self, ifindex, address, plen, peer_address); @@ -3746,7 +3746,7 @@ gboolean nm_platform_ip6_address_delete(NMPlatform *self, int ifindex, struct in6_addr address, guint8 plen) { char str_dev[TO_STRING_DEV_BUF_SIZE]; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; _CHECK_SELF(self, klass, FALSE); @@ -3754,7 +3754,7 @@ nm_platform_ip6_address_delete(NMPlatform *self, int ifindex, struct in6_addr ad g_return_val_if_fail(plen <= 128, FALSE); _LOG3D("address: deleting IPv6 address %s/%d, %s", - _nm_utils_inet6_ntop(&address, sbuf), + nm_inet6_ntop(&address, sbuf), plen, _to_string_dev(self, ifindex, str_dev, sizeof(str_dev))); return klass->ip6_address_delete(self, ifindex, address, plen); @@ -3943,9 +3943,7 @@ _ip4_addr_subnets_hash(gconstpointer ptr) NMHashState h; nm_hash_init(&h, 3282159733); - nm_hash_update_vals(&h, - addr->plen, - nm_utils_ip4_address_clear_host_address(addr->address, addr->plen)); + nm_hash_update_vals(&h, addr->plen, nm_ip4_addr_clear_host_address(addr->address, addr->plen)); return nm_hash_complete(&h); } @@ -3956,8 +3954,8 @@ _ip4_addr_subnets_equal(gconstpointer p_a, gconstpointer p_b) const NMPlatformIP4Address *b = NMP_OBJECT_CAST_IP4_ADDRESS(p_b); return a->plen == b->plen - && (nm_utils_ip4_address_clear_host_address(a->address, a->plen) - == nm_utils_ip4_address_clear_host_address(b->address, b->plen)); + && (nm_ip4_addr_clear_host_address(a->address, a->plen) + == nm_ip4_addr_clear_host_address(b->address, b->plen)); } static GHashTable * @@ -5251,15 +5249,15 @@ nm_platform_ip_route_normalize(int addr_family, NMPlatformIPRoute *route) r4 = (NMPlatformIP4Route *) route; route->metric = nm_platform_ip4_route_get_effective_metric(r4); route->metric_any = FALSE; - r4->network = nm_utils_ip4_address_clear_host_address(r4->network, r4->plen); + r4->network = nm_ip4_addr_clear_host_address(r4->network, r4->plen); r4->scope_inv = _ip_route_scope_inv_get_normalized(r4); break; case AF_INET6: r6 = (NMPlatformIP6Route *) route; route->metric = nm_platform_ip6_route_get_effective_metric(r6); route->metric_any = FALSE; - nm_utils_ip6_address_clear_host_address(&r6->network, &r6->network, r6->plen); - nm_utils_ip6_address_clear_host_address(&r6->src, &r6->src, r6->src_plen); + nm_ip6_addr_clear_host_address(&r6->network, &r6->network, r6->plen); + nm_ip6_addr_clear_host_address(&r6->src, &r6->src, r6->src_plen); break; default: nm_assert_not_reached(); @@ -5364,7 +5362,7 @@ nm_platform_ip_route_get(NMPlatform *self, char sbuf[NM_UTILS_TO_STRING_BUFFER_SIZE]; nm_auto_nmpobj NMPObject *route = NULL; int result; - char buf[NM_UTILS_INET_ADDRSTRLEN]; + char buf[NM_INET_ADDRSTRLEN]; char buf_oif[64]; _CHECK_SELF(self, klass, FALSE); @@ -5893,7 +5891,7 @@ nm_platform_link_to_string(const NMPlatformLink *link, char *buf, gsize len) char str_address[_NM_UTILS_HWADDR_LEN_MAX * 3]; char str_perm_address[_NM_UTILS_HWADDR_LEN_MAX * 3]; char str_broadcast[_NM_UTILS_HWADDR_LEN_MAX * 3]; - char str_inet6_token[NM_UTILS_INET_ADDRSTRLEN]; + char str_inet6_token[NM_INET_ADDRSTRLEN]; const char *str_link_type; if (!nm_utils_to_string_buffer_init_null(link, &buf, &len)) @@ -6186,7 +6184,7 @@ nm_platform_lnk_bond_to_string(const NMPlatformLnkBond *lnk, char *buf, gsize le char target[INET_ADDRSTRLEN]; nm_strbuf_append_c(&buf, &len, ' '); - nm_strbuf_append_str(&buf, &len, _nm_utils_inet4_ntop(lnk->arp_ip_target[i], target)); + nm_strbuf_append_str(&buf, &len, nm_inet4_ntop(lnk->arp_ip_target[i], target)); } } return buf; @@ -6196,18 +6194,18 @@ const char * nm_platform_lnk_gre_to_string(const NMPlatformLnkGre *lnk, char *buf, gsize len) { char str_local[30]; - char str_local1[NM_UTILS_INET_ADDRSTRLEN]; + char str_local1[NM_INET_ADDRSTRLEN]; char str_remote[30]; - char str_remote1[NM_UTILS_INET_ADDRSTRLEN]; + char str_remote1[NM_INET_ADDRSTRLEN]; char str_ttl[30]; char str_tos[30]; char str_parent_ifindex[30]; char str_input_flags[30]; char str_output_flags[30]; char str_input_key[30]; - char str_input_key1[NM_UTILS_INET_ADDRSTRLEN]; + char str_input_key1[NM_INET_ADDRSTRLEN]; char str_output_key[30]; - char str_output_key1[NM_UTILS_INET_ADDRSTRLEN]; + char str_output_key1[NM_INET_ADDRSTRLEN]; if (!nm_utils_to_string_buffer_init_null(lnk, &buf, &len)) return buf; @@ -6228,13 +6226,11 @@ nm_platform_lnk_gre_to_string(const NMPlatformLnkGre *lnk, char *buf, gsize len) "%s" /* okey */ "", lnk->is_tap ? "tap" : "", - lnk->remote ? nm_sprintf_buf(str_remote, - " remote %s", - _nm_utils_inet4_ntop(lnk->remote, str_remote1)) - : "", - lnk->local - ? nm_sprintf_buf(str_local, " local %s", _nm_utils_inet4_ntop(lnk->local, str_local1)) + lnk->remote + ? nm_sprintf_buf(str_remote, " remote %s", nm_inet4_ntop(lnk->remote, str_remote1)) : "", + lnk->local ? nm_sprintf_buf(str_local, " local %s", nm_inet4_ntop(lnk->local, str_local1)) + : "", lnk->parent_ifindex ? nm_sprintf_buf(str_parent_ifindex, " dev %d", lnk->parent_ifindex) : "", lnk->ttl ? nm_sprintf_buf(str_ttl, " ttl %u", lnk->ttl) : " ttl inherit", @@ -6247,12 +6243,12 @@ nm_platform_lnk_gre_to_string(const NMPlatformLnkGre *lnk, char *buf, gsize len) NM_FLAGS_HAS(lnk->input_flags, GRE_KEY) || lnk->input_key ? nm_sprintf_buf(str_input_key, " ikey %s", - _nm_utils_inet4_ntop(lnk->input_key, str_input_key1)) + nm_inet4_ntop(lnk->input_key, str_input_key1)) : "", NM_FLAGS_HAS(lnk->output_flags, GRE_KEY) || lnk->output_key ? nm_sprintf_buf(str_output_key, " okey %s", - _nm_utils_inet4_ntop(lnk->output_key, str_output_key1)) + nm_inet4_ntop(lnk->output_key, str_output_key1)) : ""); return buf; } @@ -6281,9 +6277,9 @@ const char * nm_platform_lnk_ip6tnl_to_string(const NMPlatformLnkIp6Tnl *lnk, char *buf, gsize len) { char str_local[30]; - char str_local1[NM_UTILS_INET_ADDRSTRLEN]; + char str_local1[NM_INET_ADDRSTRLEN]; char str_remote[30]; - char str_remote1[NM_UTILS_INET_ADDRSTRLEN]; + char str_remote1[NM_INET_ADDRSTRLEN]; char str_ttl[30]; char str_tclass[30]; char str_flow[30]; @@ -6300,32 +6296,32 @@ nm_platform_lnk_ip6tnl_to_string(const NMPlatformLnkIp6Tnl *lnk, char *buf, gsiz else str_type = "ip6tnl"; - g_snprintf( - buf, - len, - "%s" /* type */ - "%s" /* remote */ - "%s" /* local */ - "%s" /* parent_ifindex */ - "%s" /* ttl */ - "%s" /* tclass */ - "%s" /* encap limit */ - "%s" /* flow label */ - "%s" /* proto */ - " flags 0x%x" - "", - str_type, - nm_sprintf_buf(str_remote, " remote %s", _nm_utils_inet6_ntop(&lnk->remote, str_remote1)), - nm_sprintf_buf(str_local, " local %s", _nm_utils_inet6_ntop(&lnk->local, str_local1)), - lnk->parent_ifindex ? nm_sprintf_buf(str_parent_ifindex, " dev %d", lnk->parent_ifindex) - : "", - lnk->ttl ? nm_sprintf_buf(str_ttl, " ttl %u", lnk->ttl) : " ttl inherit", - lnk->tclass == 1 ? " tclass inherit" - : nm_sprintf_buf(str_tclass, " tclass 0x%x", lnk->tclass), - nm_sprintf_buf(str_encap, " encap-limit %u", lnk->encap_limit), - nm_sprintf_buf(str_flow, " flow-label 0x05%x", lnk->flow_label), - nm_sprintf_buf(str_proto, " proto %u", lnk->proto), - (guint) lnk->flags); + g_snprintf(buf, + len, + "%s" /* type */ + "%s" /* remote */ + "%s" /* local */ + "%s" /* parent_ifindex */ + "%s" /* ttl */ + "%s" /* tclass */ + "%s" /* encap limit */ + "%s" /* flow label */ + "%s" /* proto */ + " flags 0x%x" + "", + str_type, + nm_sprintf_buf(str_remote, " remote %s", nm_inet6_ntop(&lnk->remote, str_remote1)), + nm_sprintf_buf(str_local, " local %s", nm_inet6_ntop(&lnk->local, str_local1)), + lnk->parent_ifindex + ? nm_sprintf_buf(str_parent_ifindex, " dev %d", lnk->parent_ifindex) + : "", + lnk->ttl ? nm_sprintf_buf(str_ttl, " ttl %u", lnk->ttl) : " ttl inherit", + lnk->tclass == 1 ? " tclass inherit" + : nm_sprintf_buf(str_tclass, " tclass 0x%x", lnk->tclass), + nm_sprintf_buf(str_encap, " encap-limit %u", lnk->encap_limit), + nm_sprintf_buf(str_flow, " flow-label 0x05%x", lnk->flow_label), + nm_sprintf_buf(str_proto, " proto %u", lnk->proto), + (guint) lnk->flags); return buf; } @@ -6333,9 +6329,9 @@ const char * nm_platform_lnk_ipip_to_string(const NMPlatformLnkIpIp *lnk, char *buf, gsize len) { char str_local[30]; - char str_local1[NM_UTILS_INET_ADDRSTRLEN]; + char str_local1[NM_INET_ADDRSTRLEN]; char str_remote[30]; - char str_remote1[NM_UTILS_INET_ADDRSTRLEN]; + char str_remote1[NM_INET_ADDRSTRLEN]; char str_ttl[30]; char str_tos[30]; char str_parent_ifindex[30]; @@ -6354,13 +6350,11 @@ nm_platform_lnk_ipip_to_string(const NMPlatformLnkIpIp *lnk, char *buf, gsize le "%s" /* tos */ "%s" /* path_mtu_discovery */ "", - lnk->remote ? nm_sprintf_buf(str_remote, - " remote %s", - _nm_utils_inet4_ntop(lnk->remote, str_remote1)) - : "", - lnk->local - ? nm_sprintf_buf(str_local, " local %s", _nm_utils_inet4_ntop(lnk->local, str_local1)) + lnk->remote + ? nm_sprintf_buf(str_remote, " remote %s", nm_inet4_ntop(lnk->remote, str_remote1)) : "", + lnk->local ? nm_sprintf_buf(str_local, " local %s", nm_inet4_ntop(lnk->local, str_local1)) + : "", lnk->parent_ifindex ? nm_sprintf_buf(str_parent_ifindex, " dev %d", lnk->parent_ifindex) : "", lnk->ttl ? nm_sprintf_buf(str_ttl, " ttl %u", lnk->ttl) : " ttl inherit", @@ -6423,9 +6417,9 @@ const char * nm_platform_lnk_sit_to_string(const NMPlatformLnkSit *lnk, char *buf, gsize len) { char str_local[30]; - char str_local1[NM_UTILS_INET_ADDRSTRLEN]; + char str_local1[NM_INET_ADDRSTRLEN]; char str_remote[30]; - char str_remote1[NM_UTILS_INET_ADDRSTRLEN]; + char str_remote1[NM_INET_ADDRSTRLEN]; char str_ttl[30]; char str_tos[30]; char str_flags[30]; @@ -6448,13 +6442,11 @@ nm_platform_lnk_sit_to_string(const NMPlatformLnkSit *lnk, char *buf, gsize len) "%s" /* flags */ "%s" /* proto */ "", - lnk->remote ? nm_sprintf_buf(str_remote, - " remote %s", - _nm_utils_inet4_ntop(lnk->remote, str_remote1)) - : "", - lnk->local - ? nm_sprintf_buf(str_local, " local %s", _nm_utils_inet4_ntop(lnk->local, str_local1)) + lnk->remote + ? nm_sprintf_buf(str_remote, " remote %s", nm_inet4_ntop(lnk->remote, str_remote1)) : "", + lnk->local ? nm_sprintf_buf(str_local, " local %s", nm_inet4_ntop(lnk->local, str_local1)) + : "", lnk->parent_ifindex ? nm_sprintf_buf(str_parent_ifindex, " dev %d", lnk->parent_ifindex) : "", lnk->ttl ? nm_sprintf_buf(str_ttl, " ttl %u", lnk->ttl) : " ttl inherit", @@ -6547,7 +6539,7 @@ nm_platform_lnk_vxlan_to_string(const NMPlatformLnkVxlan *lnk, char *buf, gsize char str_dst_port[25]; char str_tos[25]; char str_ttl[25]; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; if (!nm_utils_to_string_buffer_init_null(lnk, &buf, &len)) return buf; @@ -6559,7 +6551,7 @@ nm_platform_lnk_vxlan_to_string(const NMPlatformLnkVxlan *lnk, char *buf, gsize sizeof(str_group), " %s %s", IN_MULTICAST(ntohl(lnk->group)) ? "group" : "remote", - _nm_utils_inet4_ntop(lnk->group, sbuf)); + nm_inet4_ntop(lnk->group, sbuf)); } if (IN6_IS_ADDR_UNSPECIFIED(&lnk->group6)) str_group6[0] = '\0'; @@ -6569,16 +6561,13 @@ nm_platform_lnk_vxlan_to_string(const NMPlatformLnkVxlan *lnk, char *buf, gsize " %s%s %s", IN6_IS_ADDR_MULTICAST(&lnk->group6) ? "group" : "remote", str_group[0] ? "6" : "", /* usually, a vxlan has either v4 or v6 only. */ - _nm_utils_inet6_ntop(&lnk->group6, sbuf)); + nm_inet6_ntop(&lnk->group6, sbuf)); } if (lnk->local == 0) str_local[0] = '\0'; else { - g_snprintf(str_local, - sizeof(str_local), - " local %s", - _nm_utils_inet4_ntop(lnk->local, sbuf)); + g_snprintf(str_local, sizeof(str_local), " local %s", nm_inet4_ntop(lnk->local, sbuf)); } if (IN6_IS_ADDR_UNSPECIFIED(&lnk->local6)) str_local6[0] = '\0'; @@ -6587,7 +6576,7 @@ nm_platform_lnk_vxlan_to_string(const NMPlatformLnkVxlan *lnk, char *buf, gsize sizeof(str_local6), " local%s %s", str_local[0] ? "6" : "", /* usually, a vxlan has either v4 or v6 only. */ - _nm_utils_inet6_ntop(&lnk->local6, sbuf)); + nm_inet6_ntop(&lnk->local6, sbuf)); } g_snprintf( @@ -6637,9 +6626,9 @@ nm_platform_wireguard_peer_to_string(const NMPWireGuardPeer *peer, char *buf, gs { char *buf0 = buf; gs_free char *public_key_b64 = NULL; - char s_sockaddr[NM_UTILS_INET_ADDRSTRLEN + 100]; + char s_sockaddr[NM_INET_ADDRSTRLEN + 100]; char s_endpoint[20 + sizeof(s_sockaddr)]; - char s_addr[NM_UTILS_INET_ADDRSTRLEN]; + char s_addr[NM_INET_ADDRSTRLEN]; char s_keepalive[100]; guint i; @@ -6683,7 +6672,7 @@ nm_platform_wireguard_peer_to_string(const NMPWireGuardPeer *peer, char *buf, gs nm_strbuf_append(&buf, &len, " %s/%u", - nm_utils_inet_ntop(allowed_ip->family, &allowed_ip->addr, s_addr), + nm_inet_ntop(allowed_ip->family, &allowed_ip->addr, s_addr), allowed_ip->mask); } @@ -6809,7 +6798,7 @@ nm_platform_ip4_address_to_string(const NMPlatformIP4Address *address, char *buf ? (address->use_ip4_broadcast_address ? " brd " : " brd* ") : "", broadcast_address != 0u || address->use_ip4_broadcast_address - ? _nm_utils_inet4_ntop(broadcast_address, str_broadcast) + ? nm_inet4_ntop(broadcast_address, str_broadcast) : "", str_lft_p, str_pref_p, @@ -7231,7 +7220,7 @@ nm_platform_ip6_route_to_string(const NMPlatformIP6Route *route, char *buf, gsiz route->src_plen || !IN6_IS_ADDR_UNSPECIFIED(&route->src) ? nm_sprintf_buf(s_src_all, " src %s/%u", - _nm_utils_inet6_ntop(&route->src, s_src), + nm_inet6_ntop(&route->src, s_src), (unsigned) route->src_plen) : "", _rtm_flags_to_string_full(str_rtm_flags, sizeof(str_rtm_flags), route->r_rtm_flags), @@ -7285,7 +7274,7 @@ _routing_rule_addr_to_string(char **buf, guint8 plen, gboolean is_src) { - char s_addr[NM_UTILS_INET_ADDRSTRLEN]; + char s_addr[NM_INET_ADDRSTRLEN]; gboolean is_zero; gsize addr_size; @@ -7306,7 +7295,7 @@ _routing_rule_addr_to_string(char **buf, nm_strbuf_append_str(buf, len, is_src ? " from " : " to "); - nm_strbuf_append_str(buf, len, nm_utils_inet_ntop(addr_family, addr, s_addr)); + nm_strbuf_append_str(buf, len, nm_inet_ntop(addr_family, addr, s_addr)); if (plen != (addr_size * 8)) nm_strbuf_append(buf, len, "/%u", plen); @@ -7747,7 +7736,7 @@ static NM_UTILS_FLAGS2STR_DEFINE(_mptcp_flags_to_string, const char * nm_platform_mptcp_addr_to_string(const NMPlatformMptcpAddr *mptcp_addr, char *buf, gsize len) { - char str_addr[30 + NM_UTILS_INET_ADDRSTRLEN]; + char str_addr[30 + NM_INET_ADDRSTRLEN]; char str_port[30]; char str_id[30]; char str_flags[200]; @@ -7760,7 +7749,7 @@ nm_platform_mptcp_addr_to_string(const NMPlatformMptcpAddr *mptcp_addr, char *bu if (mptcp_addr->addr_family == 0) nm_sprintf_buf(str_addr, "no-addr"); else if (NM_IN_SET(mptcp_addr->addr_family, AF_INET, AF_INET6)) - nm_utils_inet_ntop(mptcp_addr->addr_family, &mptcp_addr->addr, str_addr); + nm_inet_ntop(mptcp_addr->addr_family, &mptcp_addr->addr, str_addr); else nm_sprintf_buf(str_addr, "af %d", mptcp_addr->addr_family); @@ -8471,7 +8460,7 @@ nm_platform_lnk_wireguard_cmp(const NMPlatformLnkWireGuard *a, const NMPlatformL static int _address_pretty_sort_get_prio_4(in_addr_t addr) { - if (nm_utils_ip4_address_is_link_local(addr)) + if (nm_ip4_addr_is_link_local(addr)) return 0; return 1; } @@ -8501,8 +8490,8 @@ nm_platform_ip4_address_pretty_sort_cmp(const NMPlatformIP4Address *a1, * subnet (and thus also the primary/secondary role) is * preserved. */ - n1 = nm_utils_ip4_address_clear_host_address(a1->address, a1->plen); - n2 = nm_utils_ip4_address_clear_host_address(a2->address, a2->plen); + n1 = nm_ip4_addr_clear_host_address(a1->address, a1->plen); + n2 = nm_ip4_addr_clear_host_address(a2->address, a2->plen); NM_CMP_DIRECT_MEMCMP(&n1, &n2, sizeof(guint32)); return 0; } @@ -8637,7 +8626,7 @@ nm_platform_ip4_address_cmp(const NMPlatformIP4Address *a, case NM_PLATFORM_IP_ADDRESS_CMP_TYPE_ID: /* for IPv4 addresses, you can add the same local address with differing peer-address * (IFA_ADDRESS), provided that their net-part differs. */ - NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX(a->peer_address, b->peer_address, a->plen); + NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX(a->peer_address, b->peer_address, a->plen); return 0; case NM_PLATFORM_IP_ADDRESS_CMP_TYPE_SEMANTICALLY: case NM_PLATFORM_IP_ADDRESS_CMP_TYPE_FULL: @@ -8749,7 +8738,7 @@ nm_platform_ip4_route_hash_update(const NMPlatformIP4Route *obj, nm_hash_update_vals( h, nm_platform_ip_route_get_effective_table(NM_PLATFORM_IP_ROUTE_CAST(obj)), - nm_utils_ip4_address_clear_host_address(obj->network, obj->plen), + nm_ip4_addr_clear_host_address(obj->network, obj->plen), obj->plen, obj->metric, obj->tos, @@ -8760,7 +8749,7 @@ nm_platform_ip4_route_hash_update(const NMPlatformIP4Route *obj, h, obj->type_coerced, nm_platform_ip_route_get_effective_table(NM_PLATFORM_IP_ROUTE_CAST(obj)), - nm_utils_ip4_address_clear_host_address(obj->network, obj->plen), + nm_ip4_addr_clear_host_address(obj->network, obj->plen), obj->plen, obj->metric, obj->tos, @@ -8795,7 +8784,7 @@ nm_platform_ip4_route_hash_update(const NMPlatformIP4Route *obj, obj->type_coerced, nm_platform_ip_route_get_effective_table(NM_PLATFORM_IP_ROUTE_CAST(obj)), obj->ifindex, - nm_utils_ip4_address_clear_host_address(obj->network, obj->plen), + nm_ip4_addr_clear_host_address(obj->network, obj->plen), obj->plen, obj->metric, obj->gateway, @@ -8870,7 +8859,7 @@ nm_platform_ip4_route_cmp(const NMPlatformIP4Route *a, NM_CMP_FIELD_UNSAFE(a, b, table_any); NM_CMP_DIRECT(nm_platform_ip_route_get_effective_table(NM_PLATFORM_IP_ROUTE_CAST(a)), nm_platform_ip_route_get_effective_table(NM_PLATFORM_IP_ROUTE_CAST(b))); - NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX(a->network, b->network, MIN(a->plen, b->plen)); + NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX(a->network, b->network, MIN(a->plen, b->plen)); NM_CMP_FIELD(a, b, plen); NM_CMP_FIELD_UNSAFE(a, b, metric_any); NM_CMP_FIELD(a, b, metric); @@ -8912,7 +8901,7 @@ nm_platform_ip4_route_cmp(const NMPlatformIP4Route *a, NM_CMP_FIELD(a, b, table_coerced); NM_CMP_FIELD(a, b, ifindex); if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY) - NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX(a->network, b->network, MIN(a->plen, b->plen)); + NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX(a->network, b->network, MIN(a->plen, b->plen)); else NM_CMP_FIELD(a, b, network); NM_CMP_FIELD(a, b, plen); @@ -8968,10 +8957,10 @@ nm_platform_ip6_route_hash_update(const NMPlatformIP6Route *obj, nm_hash_update_vals( h, nm_platform_ip_route_get_effective_table(NM_PLATFORM_IP_ROUTE_CAST(obj)), - *nm_utils_ip6_address_clear_host_address(&a1, &obj->network, obj->plen), + *nm_ip6_addr_clear_host_address(&a1, &obj->network, obj->plen), obj->plen, obj->metric, - *nm_utils_ip6_address_clear_host_address(&a2, &obj->src, obj->src_plen), + *nm_ip6_addr_clear_host_address(&a2, &obj->src, obj->src_plen), obj->src_plen, NM_HASH_COMBINE_BOOLS(guint8, obj->metric_any, obj->table_any)); break; @@ -8980,10 +8969,10 @@ nm_platform_ip6_route_hash_update(const NMPlatformIP6Route *obj, h, obj->type_coerced, nm_platform_ip_route_get_effective_table(NM_PLATFORM_IP_ROUTE_CAST(obj)), - *nm_utils_ip6_address_clear_host_address(&a1, &obj->network, obj->plen), + *nm_ip6_addr_clear_host_address(&a1, &obj->network, obj->plen), obj->plen, obj->metric, - *nm_utils_ip6_address_clear_host_address(&a2, &obj->src, obj->src_plen), + *nm_ip6_addr_clear_host_address(&a2, &obj->src, obj->src_plen), obj->src_plen, NM_HASH_COMBINE_BOOLS(guint8, obj->metric_any, obj->table_any), /* on top of WEAK_ID: */ @@ -8996,12 +8985,12 @@ nm_platform_ip6_route_hash_update(const NMPlatformIP6Route *obj, obj->type_coerced, nm_platform_ip_route_get_effective_table(NM_PLATFORM_IP_ROUTE_CAST(obj)), obj->ifindex, - *nm_utils_ip6_address_clear_host_address(&a1, &obj->network, obj->plen), + *nm_ip6_addr_clear_host_address(&a1, &obj->network, obj->plen), obj->plen, obj->metric, obj->gateway, obj->pref_src, - *nm_utils_ip6_address_clear_host_address(&a2, &obj->src, obj->src_plen), + *nm_ip6_addr_clear_host_address(&a2, &obj->src, obj->src_plen), obj->src_plen, nmp_utils_ip_config_source_round_trip_rtprot(obj->rt_source), obj->mss, @@ -9072,11 +9061,11 @@ nm_platform_ip6_route_cmp(const NMPlatformIP6Route *a, NM_CMP_FIELD_UNSAFE(a, b, table_any); NM_CMP_DIRECT(nm_platform_ip_route_get_effective_table(NM_PLATFORM_IP_ROUTE_CAST(a)), nm_platform_ip_route_get_effective_table(NM_PLATFORM_IP_ROUTE_CAST(b))); - NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX(&a->network, &b->network, MIN(a->plen, b->plen)); + NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX(&a->network, &b->network, MIN(a->plen, b->plen)); NM_CMP_FIELD(a, b, plen); NM_CMP_FIELD_UNSAFE(a, b, metric_any); NM_CMP_FIELD(a, b, metric); - NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX(&a->src, &b->src, MIN(a->src_plen, b->src_plen)); + NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX(&a->src, &b->src, MIN(a->src_plen, b->src_plen)); NM_CMP_FIELD(a, b, src_plen); if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID) { NM_CMP_FIELD(a, b, ifindex); @@ -9095,7 +9084,7 @@ nm_platform_ip6_route_cmp(const NMPlatformIP6Route *a, NM_CMP_FIELD(a, b, table_coerced); NM_CMP_FIELD(a, b, ifindex); if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY) - NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX(&a->network, &b->network, MIN(a->plen, b->plen)); + NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX(&a->network, &b->network, MIN(a->plen, b->plen)); else NM_CMP_FIELD_IN6ADDR(a, b, network); NM_CMP_FIELD(a, b, plen); @@ -9104,7 +9093,7 @@ nm_platform_ip6_route_cmp(const NMPlatformIP6Route *a, NM_CMP_FIELD_IN6ADDR(a, b, gateway); NM_CMP_FIELD_IN6ADDR(a, b, pref_src); if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY) { - NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX(&a->src, &b->src, MIN(a->src_plen, b->src_plen)); + NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX(&a->src, &b->src, MIN(a->src_plen, b->src_plen)); NM_CMP_FIELD(a, b, src_plen); NM_CMP_DIRECT(nmp_utils_ip_config_source_round_trip_rtprot(a->rt_source), nmp_utils_ip_config_source_round_trip_rtprot(b->rt_source)); @@ -9473,9 +9462,9 @@ nm_platform_ip4_address_generate_device_route(const NMPlatformIP4Address *addr, if (addr->plen == 0) return NULL; - network_4 = nm_utils_ip4_address_clear_host_address(addr->peer_address, addr->plen); + network_4 = nm_ip4_addr_clear_host_address(addr->peer_address, addr->plen); - if (nm_utils_ip4_address_is_zeronet(network_4)) { + if (nm_ip4_addr_is_zeronet(network_4)) { /* Kernel doesn't add device-routes for destinations that * start with 0.x.y.z. Skip them. */ return NULL; diff --git a/src/libnm-platform/nm-platform.h b/src/libnm-platform/nm-platform.h index 90ffbed02e..e1715ad9eb 100644 --- a/src/libnm-platform/nm-platform.h +++ b/src/libnm-platform/nm-platform.h @@ -1431,7 +1431,7 @@ GType nm_platform_get_type(void); static inline in_addr_t nm_platform_ip4_broadcast_address_create(in_addr_t address, guint8 plen) { - return address | ~_nm_utils_ip4_prefix_to_netmask(plen); + return address | ~nm_ip4_addr_netmask_from_prefix(plen); } static inline in_addr_t @@ -1591,9 +1591,9 @@ nm_platform_ip4_address_get_scope(in_addr_t addr) /* For IPv4 addresses, we can set any scope we want (for any address). * However, there are scopes that make sense based on the address, * so choose those. */ - return nm_utils_ip4_address_is_loopback(addr) ? (254 /* RT_SCOPE_HOST */) - : nm_utils_ip4_address_is_link_local(addr) ? (253 /* RT_SCOPE_LINK */) - : (0 /* RT_SCOPE_UNIVERSE */); + return nm_ip4_addr_is_loopback(addr) ? (254 /* RT_SCOPE_HOST */) + : nm_ip4_addr_is_link_local(addr) ? (253 /* RT_SCOPE_LINK */) + : (0 /* RT_SCOPE_UNIVERSE */); } static inline guint8 @@ -1614,7 +1614,7 @@ nm_platform_ip_address_get_scope(int addr_family, gconstpointer addr) /* Note that this function returns the scope as we configure * it in kernel (for IPv4) or as kernel chooses it (for IPv6). * - * That means, rfc1918 private addresses nm_utils_ip_is_site_local() are + * That means, rfc1918 private addresses nm_ip_addr_is_site_local() are * considered RT_SCOPE_UNIVERSE. * * Also, the deprecated IN6_IS_ADDR_SITELOCAL() addresses (fec0::/10) diff --git a/src/libnm-platform/nmp-object.c b/src/libnm-platform/nmp-object.c index d06aa9cdf3..46d6c6e758 100644 --- a/src/libnm-platform/nmp-object.c +++ b/src/libnm-platform/nmp-object.c @@ -216,7 +216,7 @@ nm_sock_addr_union_cpy_untrusted(NMSockAddrUnion *dst, const char * nm_sock_addr_union_to_string(const NMSockAddrUnion *sa, char *buf, gsize len) { - char s_addr[NM_UTILS_INET_ADDRSTRLEN]; + char s_addr[NM_INET_ADDRSTRLEN]; char s_scope_id[40]; if (!nm_utils_to_string_buffer_init_null(sa, &buf, &len)) @@ -232,14 +232,14 @@ nm_sock_addr_union_to_string(const NMSockAddrUnion *sa, char *buf, gsize len) g_snprintf(buf, len, "%s:%u", - _nm_utils_inet4_ntop(sa->in.sin_addr.s_addr, s_addr), + nm_inet4_ntop(sa->in.sin_addr.s_addr, s_addr), (guint) htons(sa->in.sin_port)); break; case AF_INET6: g_snprintf(buf, len, "[%s%s]:%u", - _nm_utils_inet6_ntop(&sa->in6.sin6_addr, s_addr), + nm_inet6_ntop(&sa->in6.sin6_addr, s_addr), (sa->in6.sin6_scope_id != 0 ? nm_sprintf_buf(s_scope_id, "%u", sa->in6.sin6_scope_id) : ""), @@ -1106,8 +1106,8 @@ _vt_cmd_obj_to_string_lnk_wireguard(const NMPObject *obj, gsize buf_len) \ { \ plat_type *const obj = (plat_type *) _obj; \ - _nm_unused char buf1[NM_UTILS_INET_ADDRSTRLEN]; \ - _nm_unused char buf2[NM_UTILS_INET_ADDRSTRLEN]; \ + _nm_unused char buf1[NM_INET_ADDRSTRLEN]; \ + _nm_unused char buf2[NM_INET_ADDRSTRLEN]; \ \ g_snprintf(buf, buf_len, __VA_ARGS__); \ return buf; \ @@ -1116,24 +1116,23 @@ _vt_cmd_obj_to_string_lnk_wireguard(const NMPObject *obj, _vt_cmd_plobj_to_string_id(link, NMPlatformLink, "%d", obj->ifindex); -_vt_cmd_plobj_to_string_id(ip4_address, - NMPlatformIP4Address, - "%d: %s/%d%s%s", - obj->ifindex, - _nm_utils_inet4_ntop(obj->address, buf1), - obj->plen, - obj->peer_address != obj->address ? "," : "", - obj->peer_address != obj->address ? _nm_utils_inet4_ntop( - nm_utils_ip4_address_clear_host_address(obj->peer_address, - obj->plen), - buf2) - : ""); +_vt_cmd_plobj_to_string_id( + ip4_address, + NMPlatformIP4Address, + "%d: %s/%d%s%s", + obj->ifindex, + nm_inet4_ntop(obj->address, buf1), + obj->plen, + obj->peer_address != obj->address ? "," : "", + obj->peer_address != obj->address + ? nm_inet4_ntop(nm_ip4_addr_clear_host_address(obj->peer_address, obj->plen), buf2) + : ""); _vt_cmd_plobj_to_string_id(ip6_address, NMPlatformIP6Address, "%d: %s", obj->ifindex, - _nm_utils_inet6_ntop(&obj->address, buf1)); + nm_inet6_ntop(&obj->address, buf1)); _vt_cmd_plobj_to_string_id(qdisc, NMPlatformQdisc, "%d: %d", obj->ifindex, obj->parent); @@ -1637,7 +1636,7 @@ _vt_cmd_plobj_id_hash_update(ip4_address, NMPlatformIP4Address, { obj->plen, obj->address, /* for IPv4 we must also consider the net-part of the peer-address (IFA_ADDRESS) */ - nm_utils_ip4_address_clear_host_address(obj->peer_address, obj->plen)); + nm_ip4_addr_clear_host_address(obj->peer_address, obj->plen)); }); _vt_cmd_plobj_id_hash_update(ip6_address, NMPlatformIP6Address, { diff --git a/src/libnmc-setting/nm-meta-setting-desc.c b/src/libnmc-setting/nm-meta-setting-desc.c index 31beb65ef9..e9ae2b9316 100644 --- a/src/libnmc-setting/nm-meta-setting-desc.c +++ b/src/libnmc-setting/nm-meta-setting-desc.c @@ -341,7 +341,7 @@ _parse_ip_route(int family, const char *str, GError **error) for (i = 1; routev[i]; i++) { gint64 tmp64; - if (nm_utils_ipaddr_is_valid(family, routev[i])) { + if (nm_inet_is_valid(family, routev[i])) { if (metric != -1 || attrs) { g_set_error(error, 1, 0, _("the next hop ('%s') must be first"), routev[i]); return NULL; @@ -2276,7 +2276,7 @@ _multilist_validate_fcn_is_domain(const char *domain, GError **error) static const char * _multilist_validate_fcn_is_ipv4_addr_or_subnet(const char *value, GError **error) { - if (!nm_utils_parse_inaddr_prefix_bin(AF_INET, value, NULL, NULL, NULL)) { + if (!nm_inet_parse_with_prefix_bin(AF_INET, value, NULL, NULL, NULL)) { nm_utils_error_set(error, NM_UTILS_ERROR_INVALID_ARGUMENT, _("invalid IPv4 or subnet \"%s\""), @@ -3414,7 +3414,7 @@ _multilist_validate2_fcn_ip_config_dns(NMSetting *setting, const char *value, GE { int addr_family = nm_setting_ip_config_get_addr_family(NM_SETTING_IP_CONFIG(setting)); - if (!nm_utils_parse_inaddr(addr_family, value, NULL)) { + if (!nm_inet_parse_str(addr_family, value, NULL)) { nm_utils_error_set(error, NM_UTILS_ERROR_INVALID_ARGUMENT, _("invalid IPv%c address '%s'"), @@ -3541,7 +3541,7 @@ _set_fcn_ip_config_gateway(ARGS_SET_FCN) value = nm_strstrip_avoid_copy_a(300, value, &value_to_free); - if (!nm_utils_ipaddr_is_valid(addr_family, value)) { + if (!nm_inet_is_valid(addr_family, value)) { g_set_error(error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, diff --git a/src/nm-cloud-setup/main.c b/src/nm-cloud-setup/main.c index 0c452acfe3..6f4e06605a 100644 --- a/src/nm-cloud-setup/main.c +++ b/src/nm-cloud-setup/main.c @@ -343,7 +343,7 @@ _nmc_mangle_connection(NMDevice *device, NMIPRoute *route_entry; NMIPRoutingRule *rule_entry; in_addr_t gateway; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf[NM_INET_ADDRSTRLEN]; for (i = 0; i < config_data->ipv4s_len; i++) { addr_entry = nm_ip_address_new_binary(AF_INET, @@ -357,8 +357,8 @@ _nmc_mangle_connection(NMDevice *device, if (config_data->has_gateway && config_data->gateway) { gateway = config_data->gateway; } else { - gateway = nm_utils_ip4_address_clear_host_address(config_data->cidr_addr, - config_data->cidr_prefix); + gateway = + nm_ip4_addr_clear_host_address(config_data->cidr_addr, config_data->cidr_prefix); if (config_data->cidr_prefix < 32) ((guint8 *) &gateway)[3] += 1; } @@ -366,7 +366,7 @@ _nmc_mangle_connection(NMDevice *device, for (i = 0; i < config_data->ipv4s_len; i++) { in_addr_t a = config_data->ipv4s_arr[i]; - a = nm_utils_ip4_address_clear_host_address(a, config_data->cidr_prefix); + a = nm_ip4_addr_clear_host_address(a, config_data->cidr_prefix); G_STATIC_ASSERT_EXPR(sizeof(gsize) >= sizeof(in_addr_t)); if (g_hash_table_add(unique_subnets, GSIZE_TO_POINTER(a))) { @@ -381,7 +381,7 @@ _nmc_mangle_connection(NMDevice *device, rule_entry = nm_ip_routing_rule_new(AF_INET); nm_ip_routing_rule_set_priority(rule_entry, 30200 + config_data->iface_idx); nm_ip_routing_rule_set_from(rule_entry, - _nm_utils_inet4_ntop(config_data->ipv4s_arr[i], sbuf), + nm_inet4_ntop(config_data->ipv4s_arr[i], sbuf), 32); nm_ip_routing_rule_set_table(rule_entry, 30200 + config_data->iface_idx); nm_assert(nm_ip_routing_rule_validate(rule_entry, NULL)); @@ -405,7 +405,7 @@ _nmc_mangle_connection(NMDevice *device, rule_entry = nm_ip_routing_rule_new(AF_INET); nm_ip_routing_rule_set_priority(rule_entry, 30400 + config_data->iface_idx); nm_ip_routing_rule_set_from(rule_entry, - _nm_utils_inet4_ntop(config_data->ipv4s_arr[i], sbuf), + nm_inet4_ntop(config_data->ipv4s_arr[i], sbuf), 32); nm_ip_routing_rule_set_table(rule_entry, 30400 + config_data->iface_idx); nm_assert(nm_ip_routing_rule_validate(rule_entry, NULL)); diff --git a/src/nm-cloud-setup/nm-cloud-setup-utils.c b/src/nm-cloud-setup/nm-cloud-setup-utils.c index e505f8bd03..e8c9943d78 100644 --- a/src/nm-cloud-setup/nm-cloud-setup-utils.c +++ b/src/nm-cloud-setup/nm-cloud-setup-utils.c @@ -507,7 +507,7 @@ nmcs_utils_ipaddr_normalize_bin(int addr_family, g_strstrip(ad); - return nm_utils_parse_inaddr_bin(addr_family, ad, out_addr_family, out_addr_bin); + return nm_inet_parse_bin(addr_family, ad, out_addr_family, out_addr_bin); } char * @@ -518,7 +518,7 @@ nmcs_utils_ipaddr_normalize(int addr_family, const char *addr, gssize len) if (!nmcs_utils_ipaddr_normalize_bin(addr_family, addr, len, &addr_family, &ipaddr)) return NULL; - return nm_utils_inet_ntop_dup(addr_family, &ipaddr); + return nm_inet_ntop_dup(addr_family, &ipaddr); } /*****************************************************************************/ diff --git a/src/nm-cloud-setup/nmcs-provider-aliyun.c b/src/nm-cloud-setup/nmcs-provider-aliyun.c index 34ab5ecc87..4b1096094d 100644 --- a/src/nm-cloud-setup/nmcs-provider-aliyun.c +++ b/src/nm-cloud-setup/nmcs-provider-aliyun.c @@ -167,7 +167,7 @@ _get_config_fetch_done_cb(NMHttpClient *http_client, config_iface_data->ipv4s_arr = g_new(in_addr_t, len); for (i = 0; i < len; i++) { filter_chars((char *) s_addrs[i], "[]\""); - if (nm_utils_parse_inaddr_bin(AF_INET, s_addrs[i], NULL, &tmp_addr)) { + if (nm_inet_parse_bin(AF_INET, s_addrs[i], NULL, &tmp_addr)) { config_iface_data->ipv4s_arr[config_iface_data->ipv4s_len++] = tmp_addr; } } @@ -176,7 +176,7 @@ _get_config_fetch_done_cb(NMHttpClient *http_client, case GET_CONFIG_FETCH_DONE_TYPE_PRIMARY_IP_ADDRESS: - if (nm_utils_parse_inaddr_bin(AF_INET, g_bytes_get_data(response, NULL), NULL, &tmp_addr)) { + if (nm_inet_parse_bin(AF_INET, g_bytes_get_data(response, NULL), NULL, &tmp_addr)) { nm_assert(config_iface_data->priv.aliyun.primary_ip_address == 0); nm_assert(!config_iface_data->priv.aliyun.has_primary_ip_address); config_iface_data->priv.aliyun.primary_ip_address = tmp_addr; @@ -186,11 +186,11 @@ _get_config_fetch_done_cb(NMHttpClient *http_client, case GET_CONFIG_FETCH_DONE_TYPE_SUBNET_VPC_CIDR_BLOCK: - if (nm_utils_parse_inaddr_prefix_bin(AF_INET, - g_bytes_get_data(response, NULL), - NULL, - &tmp_addr, - &tmp_prefix)) { + if (nm_inet_parse_with_prefix_bin(AF_INET, + g_bytes_get_data(response, NULL), + NULL, + &tmp_addr, + &tmp_prefix)) { nm_assert(!config_iface_data->has_cidr); config_iface_data->has_cidr = TRUE; config_iface_data->cidr_addr = tmp_addr; @@ -199,20 +199,14 @@ _get_config_fetch_done_cb(NMHttpClient *http_client, case GET_CONFIG_FETCH_DONE_TYPE_NETMASK: - if (nm_utils_parse_inaddr_bin(AF_INET, - g_bytes_get_data(response, NULL), - NULL, - &netmask_bin)) { - config_iface_data->cidr_prefix = _nm_utils_ip4_netmask_to_prefix(netmask_bin); + if (nm_inet_parse_bin(AF_INET, g_bytes_get_data(response, NULL), NULL, &netmask_bin)) { + config_iface_data->cidr_prefix = nm_ip4_addr_netmask_to_prefix(netmask_bin); }; break; case GET_CONFIG_FETCH_DONE_TYPE_GATEWAY: - if (nm_utils_parse_inaddr_bin(AF_INET, - g_bytes_get_data(response, NULL), - NULL, - &gateway_bin)) { + if (nm_inet_parse_bin(AF_INET, g_bytes_get_data(response, NULL), NULL, &gateway_bin)) { config_iface_data->has_gateway = TRUE; config_iface_data->gateway = gateway_bin; }; diff --git a/src/nm-cloud-setup/nmcs-provider-azure.c b/src/nm-cloud-setup/nmcs-provider-azure.c index 9b27af288a..b59235bfee 100644 --- a/src/nm-cloud-setup/nmcs-provider-azure.c +++ b/src/nm-cloud-setup/nmcs-provider-azure.c @@ -117,7 +117,7 @@ _get_config_fetch_done_cb(NMHttpClient *http_client, gs_free_error GError *error = NULL; const char *resp_str = NULL; gsize resp_len; - char tmp_addr_str[NM_UTILS_INET_ADDRSTRLEN]; + char tmp_addr_str[NM_INET_ADDRSTRLEN]; in_addr_t tmp_addr; int tmp_prefix = -1; @@ -145,7 +145,7 @@ _get_config_fetch_done_cb(NMHttpClient *http_client, } _LOGD("interface[%" G_GSSIZE_FORMAT "]: received address %s", iface_data->intern_iface_idx, - _nm_utils_inet4_ntop(tmp_addr, tmp_addr_str)); + nm_inet4_ntop(tmp_addr, tmp_addr_str)); iface_get_config->ipv4s_arr[iface_get_config->ipv4s_len] = tmp_addr; iface_get_config->has_ipv4s = TRUE; iface_get_config->ipv4s_len++; @@ -159,7 +159,7 @@ _get_config_fetch_done_cb(NMHttpClient *http_client, } _LOGD("interface[%" G_GSSIZE_FORMAT "]: received subnet address %s", iface_data->intern_iface_idx, - _nm_utils_inet4_ntop(tmp_addr, tmp_addr_str)); + nm_inet4_ntop(tmp_addr, tmp_addr_str)); iface_get_config->cidr_addr = tmp_addr; break; diff --git a/src/nm-cloud-setup/nmcs-provider-ec2.c b/src/nm-cloud-setup/nmcs-provider-ec2.c index d6fa03118d..58d691c79e 100644 --- a/src/nm-cloud-setup/nmcs-provider-ec2.c +++ b/src/nm-cloud-setup/nmcs-provider-ec2.c @@ -151,16 +151,16 @@ _get_config_fetch_done_cb(NMHttpClient *http_client, config_iface_data->ipv4s_arr = g_new(in_addr_t, len); for (i = 0; i < len; i++) { - if (nm_utils_parse_inaddr_bin(AF_INET, s_addrs[i], NULL, &tmp_addr)) + if (nm_inet_parse_bin(AF_INET, s_addrs[i], NULL, &tmp_addr)) config_iface_data->ipv4s_arr[config_iface_data->ipv4s_len++] = tmp_addr; } } } else { - if (nm_utils_parse_inaddr_prefix_bin(AF_INET, - g_bytes_get_data(response, NULL), - NULL, - &tmp_addr, - &tmp_prefix)) { + if (nm_inet_parse_with_prefix_bin(AF_INET, + g_bytes_get_data(response, NULL), + NULL, + &tmp_addr, + &tmp_prefix)) { nm_assert(!config_iface_data->has_cidr); config_iface_data->has_cidr = TRUE; config_iface_data->cidr_prefix = tmp_prefix; diff --git a/src/nm-initrd-generator/nm-initrd-generator.h b/src/nm-initrd-generator/nm-initrd-generator.h index 4f33ac653b..a7bbbe65fa 100644 --- a/src/nm-initrd-generator/nm-initrd-generator.h +++ b/src/nm-initrd-generator/nm-initrd-generator.h @@ -21,10 +21,10 @@ get_ip_address_family(const char *str, gboolean with_prefix) return AF_UNSPEC; if (with_prefix) { - if (nm_utils_parse_inaddr_prefix_bin(AF_UNSPEC, str, &addr_family, NULL, NULL)) + if (nm_inet_parse_with_prefix_bin(AF_UNSPEC, str, &addr_family, NULL, NULL)) return addr_family; } else { - if (nm_utils_parse_inaddr_bin(AF_UNSPEC, str, &addr_family, NULL)) + if (nm_inet_parse_bin(AF_UNSPEC, str, &addr_family, NULL)) return addr_family; } diff --git a/src/nm-initrd-generator/nmi-cmdline-reader.c b/src/nm-initrd-generator/nmi-cmdline-reader.c index 34b19e45c2..985da2d30f 100644 --- a/src/nm-initrd-generator/nmi-cmdline-reader.c +++ b/src/nm-initrd-generator/nmi-cmdline-reader.c @@ -632,8 +632,8 @@ reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) gboolean is_ipv4 = client_ip_family == AF_INET; NMIPAddr addr; - if (is_ipv4 && nm_utils_parse_inaddr_bin(AF_INET, netmask, NULL, &addr)) - client_ip_prefix = _nm_utils_ip4_netmask_to_prefix(addr.addr4); + if (is_ipv4 && nm_inet_parse_bin(AF_INET, netmask, NULL, &addr)) + client_ip_prefix = nm_ip4_addr_netmask_to_prefix(addr.addr4); else client_ip_prefix = _nm_utils_ascii_str_to_int64(netmask, 10, 0, is_ipv4 ? 32 : 128, -1); @@ -646,15 +646,15 @@ reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) NMIPAddress *address = NULL; NMIPAddr addr; - if (nm_utils_parse_inaddr_prefix_bin(client_ip_family, - client_ip, - NULL, - &addr, - client_ip_prefix == -1 ? &client_ip_prefix : NULL)) { + if (nm_inet_parse_with_prefix_bin(client_ip_family, + client_ip, + NULL, + &addr, + client_ip_prefix == -1 ? &client_ip_prefix : NULL)) { if (client_ip_prefix == -1) { switch (client_ip_family) { case AF_INET: - client_ip_prefix = _nm_utils_ip4_get_default_prefix(addr.addr4); + client_ip_prefix = nm_ip4_addr_get_default_prefix(addr.addr4); break; case AF_INET6: client_ip_prefix = 64; @@ -842,7 +842,7 @@ reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) for (i = 0; i < 2; i++) { if (dns_addr_family[i] == AF_UNSPEC) break; - nm_assert(nm_utils_ipaddr_is_valid(dns_addr_family[i], dns[i])); + nm_assert(nm_inet_is_valid(dns_addr_family[i], dns[i])); nm_setting_ip_config_add_dns(NM_IS_IPv4(dns_addr_family[i]) ? s_ip4 : s_ip6, dns[i]); } @@ -964,14 +964,14 @@ reader_add_routes(Reader *reader, GPtrArray *array) connection = reader_get_default_connection(reader); if (net && *net) { - if (!nm_utils_parse_inaddr_prefix_bin(family, net, &family, &net_addr, &net_prefix)) { + if (!nm_inet_parse_with_prefix_bin(family, net, &family, &net_addr, &net_prefix)) { _LOGW(LOGD_CORE, "Unrecognized address: %s", net); continue; } } if (gateway && *gateway) { - if (!nm_utils_parse_inaddr_bin(family, gateway, &family, &gateway_addr)) { + if (!nm_inet_parse_bin(family, gateway, &family, &gateway_addr)) { _LOGW(LOGD_CORE, "Unrecognized address: %s", gateway); continue; } diff --git a/src/nm-initrd-generator/nmi-dt-reader.c b/src/nm-initrd-generator/nmi-dt-reader.c index 554f5c4d2b..77ded4ac94 100644 --- a/src/nm-initrd-generator/nmi-dt-reader.c +++ b/src/nm-initrd-generator/nmi-dt-reader.c @@ -96,7 +96,7 @@ str_addr(const char *str, int *family) { NMIPAddr addr_bin; - if (!nm_utils_parse_inaddr_bin_full(*family, TRUE, str, family, &addr_bin)) { + if (!nm_inet_parse_bin_full(*family, TRUE, str, family, &addr_bin)) { _LOGW(LOGD_CORE, "Malformed IP address: '%s'", str); return NULL; } @@ -288,7 +288,7 @@ nmi_dt_reader_parse(const char *sysfs_dir) guint32 netmask_v4; nm_ip_address_get_address_binary(netmask, &netmask_v4); - prefix = _nm_utils_ip4_netmask_to_prefix(netmask_v4); + prefix = nm_ip4_addr_netmask_to_prefix(netmask_v4); } if (prefix == -1) diff --git a/src/nm-initrd-generator/nmi-ibft-reader.c b/src/nm-initrd-generator/nmi-ibft-reader.c index 5e4b1bb305..37e2a20c68 100644 --- a/src/nm-initrd-generator/nmi-ibft-reader.c +++ b/src/nm-initrd-generator/nmi-ibft-reader.c @@ -217,7 +217,7 @@ ip_setting_add_from_block(GHashTable *nic, NMConnection *connection, GError **er FALSE, NULL); - if (s_gateway && !nm_utils_ipaddr_is_valid(family, s_gateway)) { + if (s_gateway && !nm_inet_is_valid(family, s_gateway)) { g_set_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, @@ -226,7 +226,7 @@ ip_setting_add_from_block(GHashTable *nic, NMConnection *connection, GError **er return FALSE; } - if (s_dns1 && !nm_utils_ipaddr_is_valid(family, s_dns1)) { + if (s_dns1 && !nm_inet_is_valid(family, s_dns1)) { g_set_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, @@ -235,7 +235,7 @@ ip_setting_add_from_block(GHashTable *nic, NMConnection *connection, GError **er return FALSE; } - if (s_dns2 && !nm_utils_ipaddr_is_valid(family, s_dns2)) { + if (s_dns2 && !nm_inet_is_valid(family, s_dns2)) { g_set_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, diff --git a/src/nmtui/nm-editor-bindings.c b/src/nmtui/nm-editor-bindings.c index 22ffdfd598..f1d92adebc 100644 --- a/src/nmtui/nm-editor-bindings.c +++ b/src/nmtui/nm-editor-bindings.c @@ -116,7 +116,7 @@ ip_addresses_with_prefix_from_strv(GBinding *binding, } else addr = addrs->pdata[i]; - if (!nm_utils_parse_inaddr_prefix(addr_family, strings[i], &addrstr, &prefix)) { + if (!nm_inet_parse_with_prefix_str(addr_family, strings[i], &addrstr, &prefix)) { g_ptr_array_unref(addrs); return FALSE; } @@ -126,7 +126,7 @@ ip_addresses_with_prefix_from_strv(GBinding *binding, in_addr_t v4; inet_pton(addr_family, addrstr, &v4); - if (nm_utils_ip_is_site_local(AF_INET, &v4)) + if (nm_ip_addr_is_site_local(AF_INET, &v4)) prefix = nm_utils_ip4_get_default_prefix(v4); else prefix = 32; @@ -194,7 +194,7 @@ ip_addresses_check_and_copy(GBinding *binding, strings = g_value_get_boxed(source_value); for (i = 0; strings[i]; i++) { - if (!nm_utils_ipaddr_is_valid(addr_family, strings[i])) + if (!nm_inet_is_valid(addr_family, strings[i])) return FALSE; } @@ -256,7 +256,7 @@ ip_gateway_from_string(GBinding *binding, const char *gateway; gateway = g_value_get_string(source_value); - if (gateway && !nm_utils_ipaddr_is_valid(addr_family, gateway)) + if (gateway && !nm_inet_is_valid(addr_family, gateway)) gateway = NULL; g_value_set_string(target_value, gateway); @@ -428,7 +428,7 @@ ip_route_transform_from_dest_string(GBinding *binding, int prefix; text = g_value_get_string(source_value); - if (!nm_utils_parse_inaddr_prefix(addr_family, text, &addrstr, &prefix)) + if (!nm_inet_parse_with_prefix_str(addr_family, text, &addrstr, &prefix)) return FALSE; /* Fetch the original property value */ @@ -442,9 +442,9 @@ ip_route_transform_from_dest_string(GBinding *binding, in_addr_t v4; inet_pton(addr_family, addrstr, &v4); - if (nm_utils_ip_is_site_local(AF_INET, &v4)) { + if (nm_ip_addr_is_site_local(AF_INET, &v4)) { prefix = nm_utils_ip4_get_default_prefix(v4); - if (v4 & (~_nm_utils_ip4_prefix_to_netmask(prefix))) + if (v4 & (~nm_ip4_addr_netmask_from_prefix(prefix))) prefix = 32; } else prefix = 32; @@ -472,7 +472,7 @@ ip_route_transform_from_next_hop_string(GBinding *binding, text = g_value_get_string(source_value); if (*text) { - if (!nm_utils_ipaddr_is_valid(addr_family, text)) + if (!nm_inet_is_valid(addr_family, text)) return FALSE; } else text = NULL; diff --git a/src/nmtui/nmt-ip-entry.c b/src/nmtui/nmt-ip-entry.c index 9bd0f12ddf..9bac888b84 100644 --- a/src/nmtui/nmt-ip-entry.c +++ b/src/nmtui/nmt-ip-entry.c @@ -110,8 +110,8 @@ ip_entry_validate(NmtNewtEntry *entry, const char *text, gpointer user_data) if (!*text) return priv->optional; if (priv->prefix) - return nm_utils_parse_inaddr_prefix(priv->family, text, NULL, NULL); - return nm_utils_parse_inaddr(priv->family, text, NULL); + return nm_inet_parse_with_prefix_str(priv->family, text, NULL, NULL); + return nm_inet_parse_str(priv->family, text, NULL); } static void -- cgit v1.2.1 From 232df1c08dc8c48bc23d61820044f7bd3785c04f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 25 Aug 2022 12:51:11 +0200 Subject: glib-aux/tests: test nm_ip_addr_is_site_local() --- src/libnm-glib-aux/tests/test-shared-general.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libnm-glib-aux/tests/test-shared-general.c b/src/libnm-glib-aux/tests/test-shared-general.c index ef5a645868..af4354403f 100644 --- a/src/libnm-glib-aux/tests/test-shared-general.c +++ b/src/libnm-glib-aux/tests/test-shared-general.c @@ -2201,6 +2201,19 @@ test_hostname_is_valid(void) /*****************************************************************************/ +static void +test_inet_utils(void) +{ + g_assert(nm_ip_addr_is_site_local(AF_INET, nmtst_inet_from_string(AF_INET, "172.16.0.1"))); + g_assert(nm_ip_addr_is_site_local(AF_INET, nmtst_inet_from_string(AF_INET, "172.17.0.1"))); + g_assert(nm_ip_addr_is_site_local(AF_INET, nmtst_inet_from_string(AF_INET, "192.168.7.5"))); + g_assert(!nm_ip_addr_is_site_local(AF_INET, nmtst_inet_from_string(AF_INET, "192.0.7.5"))); + g_assert(nm_ip_addr_is_site_local(AF_INET6, nmtst_inet_from_string(AF_INET6, "fec0::"))); + g_assert(!nm_ip_addr_is_site_local(AF_INET6, nmtst_inet_from_string(AF_INET6, "fc00::"))); +} + +/*****************************************************************************/ + NMTST_DEFINE(); int @@ -2246,6 +2259,7 @@ main(int argc, char **argv) g_test_add_func("/general/test_path_startswith", test_path_startswith); g_test_add_func("/general/test_path_simplify", test_path_simplify); g_test_add_func("/general/test_hostname_is_valid", test_hostname_is_valid); + g_test_add_func("/general/test_inet_utils", test_inet_utils); return g_test_run(); } -- cgit v1.2.1 From b02aeaf2f3e0127d9ffa8fb1d960c5cf4014eb1f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 19 Aug 2022 13:26:14 +0200 Subject: glib-aux: fix various nm_ip_addr_*() functions for unaligned addresses Most of our nm_ip_addr_*() functions take an opaque pointer, that can be either in_addr_t, struct in6_addr or NMIPAddr. They also tend to support that their argument pointer is not aligned. The reason is not very strong, except that usually it's simple to support and it allows the caller to use those low-level functions for pointers of unknown alignment (e.g. from a package on the network). Fix a few cases for that. --- src/libnm-glib-aux/nm-inet-utils.c | 38 ++++++++++++++++++++------------ src/libnm-glib-aux/nm-inet-utils.h | 45 +++++++++++++++++++------------------- 2 files changed, 46 insertions(+), 37 deletions(-) diff --git a/src/libnm-glib-aux/nm-inet-utils.c b/src/libnm-glib-aux/nm-inet-utils.c index f8b287d086..3e5fe4496a 100644 --- a/src/libnm-glib-aux/nm-inet-utils.c +++ b/src/libnm-glib-aux/nm-inet-utils.c @@ -138,20 +138,22 @@ nm_ip4_addr_get_default_prefix(in_addr_t ip) gboolean nm_ip_addr_is_site_local(int addr_family, const void *address) { - in_addr_t addr4; + NMIPAddr a; + + nm_ip_addr_set(addr_family, &a, address); switch (addr_family) { case AF_INET: /* RFC1918 private addresses * 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 */ - addr4 = ntohl(*((const in_addr_t *) address)); - return (addr4 & 0xff000000) == 0x0a000000 || (addr4 & 0xfff00000) == 0xac100000 - || (addr4 & 0xffff0000) == 0xc0a80000; + return (a.addr4 & htonl(0xff000000)) == htonl(0x0a000000) + || (a.addr4 & htonl(0xfff00000)) == htonl(0xac100000) + || (a.addr4 & htonl(0xffff0000)) == htonl(0xc0a80000); case AF_INET6: /* IN6_IS_ADDR_SITELOCAL() is for deprecated fec0::/10 addresses (see rfc3879, 4.). - * Note that for unique local IPv6 addresses (ULA, fc00::/7) this returns false, - * which may or may not be a bug. */ - return IN6_IS_ADDR_SITELOCAL(address); + * Note that for unique local IPv6 addresses (ULA, fc00::/7) this returns false. + * This may or may not be a bug of this function. */ + return IN6_IS_ADDR_SITELOCAL(&a.addr6); default: g_return_val_if_reached(FALSE); } @@ -169,25 +171,33 @@ nm_ip6_addr_is_ula(const struct in6_addr *address) gconstpointer nm_ip_addr_clear_host_address(int family, gpointer dst, gconstpointer src, guint32 plen) { + NMIPAddr a; + NMIPAddr a2; + g_return_val_if_fail(dst, NULL); + if (!src) { + /* allow "self-assignment", by specifying %NULL as source. */ + src = dst; + } + + nm_ip_addr_set(family, &a, src); + switch (family) { case AF_INET: g_return_val_if_fail(plen <= 32, NULL); - if (!src) { - /* allow "self-assignment", by specifying %NULL as source. */ - src = dst; - } - - *((guint32 *) dst) = nm_ip4_addr_clear_host_address(*((guint32 *) src), plen); + a2.addr4 = nm_ip4_addr_clear_host_address(a.addr4, plen); break; case AF_INET6: - nm_ip6_addr_clear_host_address(dst, src, plen); + nm_ip6_addr_clear_host_address(&a2.addr6, &a.addr6, plen); break; default: g_return_val_if_reached(NULL); } + + nm_ip_addr_set(family, dst, &a2); + return dst; } diff --git a/src/libnm-glib-aux/nm-inet-utils.h b/src/libnm-glib-aux/nm-inet-utils.h index 6530f4222f..d9246d459b 100644 --- a/src/libnm-glib-aux/nm-inet-utils.h +++ b/src/libnm-glib-aux/nm-inet-utils.h @@ -50,23 +50,6 @@ nm_ip_addr_equal(int addr_family, gconstpointer a, gconstpointer b) return nm_ip_addr_cmp(addr_family, a, b) == 0; } -static inline gboolean -nm_ip_addr_is_null(int addr_family, gconstpointer addr) -{ - nm_assert(addr); - - if (NM_IS_IPv4(addr_family)) { - in_addr_t t; - - /* also for in_addr_t type (AF_INET), we accept that the pointer might - * be unaligned. */ - memcpy(&t, addr, sizeof(t)); - return t == 0; - } - - return IN6_IS_ADDR_UNSPECIFIED((const struct in6_addr *) addr); -} - static inline void nm_ip_addr_set(int addr_family, gpointer dst, gconstpointer src) { @@ -84,6 +67,19 @@ nm_ip_addr_set(int addr_family, gpointer dst, gconstpointer src) * uninitalized bytes. Avoid that by using nm_ip_addr_init() instead. */ } +static inline gboolean +nm_ip_addr_is_null(int addr_family, gconstpointer addr) +{ + NMIPAddr a; + + nm_ip_addr_set(addr_family, &a, addr); + + if (NM_IS_IPv4(addr_family)) + return a.addr4 == 0; + + return IN6_IS_ADDR_UNSPECIFIED(&a.addr6); +} + static inline NMIPAddr nm_ip_addr_init(int addr_family, gconstpointer src) { @@ -201,15 +197,18 @@ nm_ip6_addr_same_prefix(const struct in6_addr *addr_a, const struct in6_addr *ad static inline int nm_ip_addr_same_prefix_cmp(int addr_family, gconstpointer addr_a, gconstpointer addr_b, guint8 plen) { + NMIPAddr a; + NMIPAddr b; + NM_CMP_SELF(addr_a, addr_b); - if (NM_IS_IPv4(addr_family)) { - return nm_ip4_addr_same_prefix_cmp(*((const in_addr_t *) addr_a), - *((const in_addr_t *) addr_b), - plen); - } + nm_ip_addr_set(addr_family, &a, addr_a); + nm_ip_addr_set(addr_family, &b, addr_b); + + if (NM_IS_IPv4(addr_family)) + return nm_ip4_addr_same_prefix_cmp(a.addr4, b.addr4, plen); - return nm_ip6_addr_same_prefix_cmp(addr_a, addr_b, plen); + return nm_ip6_addr_same_prefix_cmp(&a.addr6, &b.addr6, plen); } static inline gboolean -- cgit v1.2.1 From 0e3ab2782ab3605d80914ae4b24532cb8e82e511 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 19 Aug 2022 14:45:46 +0200 Subject: glib-aux: simplify nm_inet_parse_str() by using nm_inet_parse_bin() --- src/libnm-glib-aux/nm-inet-utils.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/libnm-glib-aux/nm-inet-utils.c b/src/libnm-glib-aux/nm-inet-utils.c index 3e5fe4496a..2ede87baf9 100644 --- a/src/libnm-glib-aux/nm-inet-utils.c +++ b/src/libnm-glib-aux/nm-inet-utils.c @@ -425,20 +425,11 @@ gboolean nm_inet_parse_str(int addr_family, const char *text, char **out_addr) { NMIPAddr addrbin; - char addrstr_buf[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)]; - g_return_val_if_fail(text, FALSE); - - if (addr_family == AF_UNSPEC) - addr_family = strchr(text, ':') ? AF_INET6 : AF_INET; - else - g_return_val_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6), FALSE); - - if (inet_pton(addr_family, text, &addrbin) != 1) + if (!nm_inet_parse_bin(addr_family, text, &addr_family, &addrbin)) return FALSE; - NM_SET_OUT(out_addr, - g_strdup(inet_ntop(addr_family, &addrbin, addrstr_buf, sizeof(addrstr_buf)))); + NM_SET_OUT(out_addr, nm_inet_ntop_dup(addr_family, &addrbin)); return TRUE; } @@ -492,12 +483,11 @@ gboolean nm_inet_parse_with_prefix_str(int addr_family, const char *text, char **out_addr, int *out_prefix) { NMIPAddr addrbin; - char addrstr_buf[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)]; if (!nm_inet_parse_with_prefix_bin(addr_family, text, &addr_family, &addrbin, out_prefix)) return FALSE; - NM_SET_OUT(out_addr, - g_strdup(inet_ntop(addr_family, &addrbin, addrstr_buf, sizeof(addrstr_buf)))); + + NM_SET_OUT(out_addr, nm_inet_ntop_dup(addr_family, &addrbin)); return TRUE; } -- cgit v1.2.1 From 97a2a566b4780b05e5a00db609643a24fc92fb99 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 25 Aug 2022 19:20:58 +0200 Subject: glib-aux/trivial: rename function for consistency --- src/libnm-glib-aux/nm-shared-utils.h | 1 + src/libnm-glib-aux/tests/test-shared-general.c | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index cb3f7f9ad5..892d0d3012 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -274,6 +274,7 @@ gboolean nm_utils_get_ipv6_interface_identifier(NMLinkType link_type, NMUtilsIPv6IfaceId *out_iid); /*****************************************************************************/ + gboolean nm_utils_memeqzero(gconstpointer data, gsize length); /*****************************************************************************/ diff --git a/src/libnm-glib-aux/tests/test-shared-general.c b/src/libnm-glib-aux/tests/test-shared-general.c index af4354403f..e6e57c5218 100644 --- a/src/libnm-glib-aux/tests/test-shared-general.c +++ b/src/libnm-glib-aux/tests/test-shared-general.c @@ -251,7 +251,7 @@ test_nm_strndup_a(void) /*****************************************************************************/ static void -test_nm_utils_ip4_address_is_loopback(void) +test_nm_ip4_addr_is_loopback(void) { g_assert(nm_ip4_addr_is_loopback(nmtst_inet4_from_string("127.0.0.0"))); g_assert(nm_ip4_addr_is_loopback(nmtst_inet4_from_string("127.0.0.1"))); @@ -264,7 +264,7 @@ test_nm_utils_ip4_address_is_loopback(void) /*****************************************************************************/ static void -test_nm_utils_ip4_prefix_to_netmask(void) +test_nm_ip4_addr_netmask_from_prefix(void) { g_assert_cmpint(nm_ip4_addr_netmask_from_prefix(0), ==, nmtst_inet4_from_string("0.0.0.0")); g_assert_cmpint(nm_ip4_addr_netmask_from_prefix(1), ==, nmtst_inet4_from_string("128.0.0.0")); @@ -2228,10 +2228,9 @@ main(int argc, char **argv) g_test_add_func("/general/test_nm_make_strv", test_make_strv); g_test_add_func("/general/test_nm_strdup_int", test_nm_strdup_int); g_test_add_func("/general/test_nm_strndup_a", test_nm_strndup_a); - g_test_add_func("/general/test_nm_utils_ip4_address_is_loopback", - test_nm_utils_ip4_address_is_loopback); - g_test_add_func("/general/test_nm_utils_ip4_prefix_to_netmask", - test_nm_utils_ip4_prefix_to_netmask); + g_test_add_func("/general/test_nm_ip4_addr_is_loopback", test_nm_ip4_addr_is_loopback); + g_test_add_func("/general/test_nm_ip4_addr_netmask_from_prefix", + test_nm_ip4_addr_netmask_from_prefix); g_test_add_func("/general/test_unaligned", test_unaligned); g_test_add_func("/general/test_strv_cmp", test_strv_cmp); g_test_add_func("/general/test_strstrip_avoid_copy", test_strstrip_avoid_copy); -- cgit v1.2.1 From 04a97e4e854c7d77aced2716f58b7d4e0777f016 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 25 Aug 2022 19:43:40 +0200 Subject: std-aux: workaround maybe uninitialized warning with LTO on nm_ip_addr_is_null() LTO without assertion enabled, thinks that certain code paths result in uninitialized code. Technically, it's not wrong, in practice those are only in cases where we already failed an assertion. In function 'nm_ip_addr_is_null', inlined from 'canonicalize_ip_binary' at src/libnm-core-impl/nm-setting-ip-config.c:67:21, inlined from 'nm_ip_route_set_next_hop_binary' at src/libnm-core-impl/nm-setting-ip-config.c:1062:23: ./src/libnm-glib-aux/nm-inet-utils.h:80:12: error: 'a' may be used uninitialized [-Werror=maybe-uninitialized] 80 | return IN6_IS_ADDR_UNSPECIFIED(&a.addr6); | ^ src/libnm-core-impl/nm-setting-ip-config.c: In function 'nm_ip_route_set_next_hop_binary': ./src/libnm-glib-aux/nm-inet-utils.h:73:14: note: 'a' declared here 73 | NMIPAddr a; | ^ Try to workaround that by letting nm_utils_addr_family_to_size() always return a non-zero size. This is ugly, because in the assertion case fail we might now also get an additional memory corruption that could have been avoided by returning zero. However, it probably doesn't matter, because in this scenario we are already in a bad situation. Fixes: b02aeaf2f3e0 ('glib-aux: fix various nm_ip_addr_*() functions for unaligned addresses') --- src/libnm-std-aux/nm-std-aux.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h index 77243ab186..95724252cb 100644 --- a/src/libnm-std-aux/nm-std-aux.h +++ b/src/libnm-std-aux/nm-std-aux.h @@ -1298,13 +1298,10 @@ nm_utils_addr_family_other(int addr_family) static inline size_t nm_utils_addr_family_to_size(int addr_family) { - switch (addr_family) { - case NM_AF_INET: - return NM_AF_INET_SIZE; - case NM_AF_INET6: + if (!NM_IS_IPv4(addr_family)) return NM_AF_INET6_SIZE; - } - return nm_assert_unreachable_val(0); + else + return NM_AF_INET_SIZE; } static inline size_t -- cgit v1.2.1 From c00873e08f4d0bc4a3f0b8a93beb793fcab78afa Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 25 Aug 2022 09:40:46 +0200 Subject: mptcp: rework "connection.mptcp-flags" for enabling MPTCP 1) The "enabled-on-global-iface" flag was odd. Instead, have only and "enabled" flag and skip (by default) endpoints on interface that have no default route. With the new flag "also-without-default-route", this can be overruled. So previous "enabled-on-global-default" now is the same as "enabled", and "enabled" from before behaves now like "enabled,also-without-default-route". 2) What was also odd, as that the fallback default value for the flags depends on "/proc/sys/net/mptcp/enabled". There was not one fixed fallback default, instead the used fallback value was either "enabled-on-global-iface,subflow" or "disabled". Usually that is not a problem (e.g. the default value for "ipv6.ip6-privacy" also depends on use_tempaddr sysctl). In this case it is a problem, because the mptcp-flags (for better or worse) encode different things at the same time. Consider that the mptcp-flags can also have their default configured in "NetworkManager.conf", a user who wants to switch the address flags could previously do: [connection.mptcp] connection.mptcp-flags=0x32 # enabled-on-global-iface,signal,subflow but then the global toggle "/proc/sys/net/mptcp/enabled" was no longer honored. That means, MPTCP handling was always on, even if the sysctl was disabled. Now, "enabled" means that it's only enabled if the sysctl is enabled too. Now the user could write to "NetworkManager.conf" [connection.mptcp] connection.mptcp-flags=0x32 # enabled,signal,subflow and MPTCP handling would still be disabled unless the sysctl is enabled. There is now also a new flag "also-without-sysctl", so if you want to really enable MPTCP handling regardless of the sysctl, you can. The point of that might be, that we still can configure endpoints, even if kernel won't do anything with them. Then you could just flip the sysctl, and it would start working (as NetworkManager configured the endpoints already). Fixes: eb083eece5a2 ('all: add NMMptcpFlags and connection.mptcp-flags property') --- man/NetworkManager.conf.xml | 2 +- src/core/devices/nm-device.c | 47 ++++++++++++++---------- src/core/nm-l3cfg.c | 8 ++-- src/libnm-core-aux-intern/nm-libnm-core-utils.c | 10 +---- src/libnm-core-aux-intern/nm-libnm-core-utils.h | 12 +++--- src/libnm-core-impl/nm-setting-connection.c | 47 +++++++++++------------- src/libnm-core-public/nm-dbus-interface.h | 27 +++++++++++--- src/libnmc-setting/settings-docs.h.in | 2 +- src/nmcli/generate-docs-nm-settings-nmcli.xml.in | 2 +- 9 files changed, 85 insertions(+), 72 deletions(-) diff --git a/man/NetworkManager.conf.xml b/man/NetworkManager.conf.xml index 6a0fd7b1c1..301172e4cc 100644 --- a/man/NetworkManager.conf.xml +++ b/man/NetworkManager.conf.xml @@ -868,7 +868,7 @@ ipv6.ip6-privacy=0 connection.mptcp-flags - If unspecified, the fallback is either 0 ("disabled") or 0x22 ("enabled-on-global-iface,subflow"), depending on /proc/sys/net/mptcp/enabled. + If unspecified, the fallback is 0x22 ("enabled,subflow"). Note that if sysctl /proc/sys/net/mptcp/enabled is disabled, NetworkManager will still not configure endpoints. connection.dns-over-tls diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 0635d14431..aa7481c71e 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -1410,8 +1410,6 @@ _prop_get_connection_mptcp_flags(NMDevice *self) if (connection) { mptcp_flags = nm_setting_connection_get_mptcp_flags(nm_connection_get_setting_connection(connection)); - if (mptcp_flags != NM_MPTCP_FLAGS_NONE) - mptcp_flags = nm_mptcp_flags_normalize(mptcp_flags); } if (mptcp_flags == NM_MPTCP_FLAGS_NONE) { @@ -1423,28 +1421,39 @@ _prop_get_connection_mptcp_flags(NMDevice *self) 0, G_MAXINT64, NM_MPTCP_FLAGS_NONE); - /* We filter out all invalid settings and accept it. Somewhat intentionally, we don't do a - * strict parsing of the value to support forward compatibility. */ - if (v != NM_MPTCP_FLAGS_NONE) - mptcp_flags = nm_mptcp_flags_normalize(v); + if (v != NM_MPTCP_FLAGS_NONE) { + /* We silently ignore all invalid flags (and will normalize them away below). */ + mptcp_flags = (NMMptcpFlags) v; + if (mptcp_flags == NM_MPTCP_FLAGS_NONE) + mptcp_flags = NM_MPTCP_FLAGS_ENABLED; + } } - if (mptcp_flags == NM_MPTCP_FLAGS_NONE) { - gint32 v; - - v = nm_platform_sysctl_get_int32(nm_device_get_platform(self), - NMP_SYSCTL_PATHID_ABSOLUTE("/proc/sys/net/mptcp/enabled"), - -1); - if (v > 0) { - /* if MPTCP is enabled via the sysctl, we use the default. */ - mptcp_flags = _NM_MPTCP_FLAGS_DEFAULT; + if (mptcp_flags == NM_MPTCP_FLAGS_NONE) + mptcp_flags = _NM_MPTCP_FLAGS_DEFAULT; + + mptcp_flags = nm_mptcp_flags_normalize(mptcp_flags); + + if (!NM_FLAGS_HAS(mptcp_flags, NM_MPTCP_FLAGS_DISABLED)) { + if (!NM_FLAGS_HAS(mptcp_flags, NM_MPTCP_FLAGS_ALSO_WITHOUT_SYSCTL)) { + guint32 v; + + /* If enabled, but without "also-without-sysctl", then MPTCP is still + * disabled, if the sysctl says so... + * + * We evaluate this here. The point is that the decision is then cached + * until deactivation/reapply. The user can toggle the sysctl any time, + * but we only pick it up at certain moments (now). */ + v = nm_platform_sysctl_get_int32( + nm_device_get_platform(self), + NMP_SYSCTL_PATHID_ABSOLUTE("/proc/sys/net/mptcp/enabled"), + -1); + if (v <= 0) + mptcp_flags = NM_MPTCP_FLAGS_DISABLED; } else - mptcp_flags = NM_MPTCP_FLAGS_DISABLED; + mptcp_flags = NM_FLAGS_UNSET(mptcp_flags, NM_MPTCP_FLAGS_ALSO_WITHOUT_SYSCTL); } - nm_assert(mptcp_flags != NM_MPTCP_FLAGS_NONE - && mptcp_flags == nm_mptcp_flags_normalize(mptcp_flags)); - return mptcp_flags; } diff --git a/src/core/nm-l3cfg.c b/src/core/nm-l3cfg.c index 3c054b9ef8..963e381b14 100644 --- a/src/core/nm-l3cfg.c +++ b/src/core/nm-l3cfg.c @@ -4307,13 +4307,13 @@ _l3_commit_mptcp_af(NML3Cfg *self, if (mptcp_flags == NM_MPTCP_FLAGS_NONE || NM_FLAGS_HAS(mptcp_flags, NM_MPTCP_FLAGS_DISABLED)) mptcp_flags = NM_MPTCP_FLAGS_DISABLED; - else if (NM_FLAGS_HAS(mptcp_flags, NM_MPTCP_FLAGS_ENABLED_ON_GLOBAL_IFACE)) { - /* Whether MPTCP is enabled/disabled, depends on whether we have a unicast default - * route (in the main routing table). */ + else if (!NM_FLAGS_HAS(mptcp_flags, NM_MPTCP_FLAGS_ALSO_WITHOUT_DEFAULT_ROUTE)) { + /* Whether MPTCP is enabled/disabled (per address family), depends on whether we have a unicast + * default route (in the main routing table). */ if (self->priv.p->combined_l3cd_commited && nm_l3_config_data_get_best_default_route(self->priv.p->combined_l3cd_commited, addr_family)) - mptcp_flags = NM_FLAGS_UNSET(mptcp_flags, NM_MPTCP_FLAGS_ENABLED_ON_GLOBAL_IFACE) + mptcp_flags = NM_FLAGS_UNSET(mptcp_flags, NM_MPTCP_FLAGS_ALSO_WITHOUT_DEFAULT_ROUTE) | NM_MPTCP_FLAGS_ENABLED; else mptcp_flags = NM_MPTCP_FLAGS_DISABLED; diff --git a/src/libnm-core-aux-intern/nm-libnm-core-utils.c b/src/libnm-core-aux-intern/nm-libnm-core-utils.c index 4fdf9d6d4e..1febe5dfd8 100644 --- a/src/libnm-core-aux-intern/nm-libnm-core-utils.c +++ b/src/libnm-core-aux-intern/nm-libnm-core-utils.c @@ -512,14 +512,8 @@ nm_mptcp_flags_normalize(NMMptcpFlags flags) /* Clear all unknown flags. */ flags &= _NM_MPTCP_FLAGS_ALL; - /* We must either set "enabled-on-global-iface" or "enabled". The - * former takes precedence, if they are both set. - * - * If neither is set, we default to "enabled". */ - if (NM_FLAGS_HAS(flags, NM_MPTCP_FLAGS_ENABLED_ON_GLOBAL_IFACE)) - flags = NM_FLAGS_UNSET(flags, NM_MPTCP_FLAGS_ENABLED); - else - flags = NM_FLAGS_SET(flags, NM_MPTCP_FLAGS_ENABLED); + /* Not disabled means enabled. */ + flags |= NM_MPTCP_FLAGS_ENABLED; if (NM_FLAGS_ALL(flags, NM_MPTCP_FLAGS_SIGNAL | NM_MPTCP_FLAGS_FULLMESH)) flags = NM_FLAGS_UNSET(flags, NM_MPTCP_FLAGS_FULLMESH); diff --git a/src/libnm-core-aux-intern/nm-libnm-core-utils.h b/src/libnm-core-aux-intern/nm-libnm-core-utils.h index 5c827c01b5..0208bfdb24 100644 --- a/src/libnm-core-aux-intern/nm-libnm-core-utils.h +++ b/src/libnm-core-aux-intern/nm-libnm-core-utils.h @@ -269,13 +269,13 @@ gpointer _nm_connection_new_setting(NMConnection *connection, GType gtype); /*****************************************************************************/ -#define _NM_MPTCP_FLAGS_ALL \ - ((NMMptcpFlags) (NM_MPTCP_FLAGS_DISABLED | NM_MPTCP_FLAGS_ENABLED_ON_GLOBAL_IFACE \ - | NM_MPTCP_FLAGS_ENABLED | NM_MPTCP_FLAGS_SIGNAL | NM_MPTCP_FLAGS_SUBFLOW \ - | NM_MPTCP_FLAGS_BACKUP | NM_MPTCP_FLAGS_FULLMESH)) +#define _NM_MPTCP_FLAGS_ALL \ + ((NMMptcpFlags) (NM_MPTCP_FLAGS_DISABLED | NM_MPTCP_FLAGS_ENABLED \ + | NM_MPTCP_FLAGS_ALSO_WITHOUT_SYSCTL \ + | NM_MPTCP_FLAGS_ALSO_WITHOUT_DEFAULT_ROUTE | NM_MPTCP_FLAGS_SIGNAL \ + | NM_MPTCP_FLAGS_SUBFLOW | NM_MPTCP_FLAGS_BACKUP | NM_MPTCP_FLAGS_FULLMESH)) -#define _NM_MPTCP_FLAGS_DEFAULT \ - ((NMMptcpFlags) (NM_MPTCP_FLAGS_ENABLED_ON_GLOBAL_IFACE | NM_MPTCP_FLAGS_SUBFLOW)) +#define _NM_MPTCP_FLAGS_DEFAULT ((NMMptcpFlags) (NM_MPTCP_FLAGS_ENABLED | NM_MPTCP_FLAGS_SUBFLOW)) NMMptcpFlags nm_mptcp_flags_normalize(NMMptcpFlags flags); diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index 0d307be399..cbce1c121d 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -1402,19 +1402,6 @@ after_interface_name: } else { guint32 f; - if (NM_FLAGS_ALL(priv->mptcp_flags, - NM_MPTCP_FLAGS_ENABLED_ON_GLOBAL_IFACE | NM_MPTCP_FLAGS_ENABLED)) { - g_set_error_literal( - error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("\"enabled\" and \"enabled-on-global-iface\" flag cannot be set together")); - g_prefix_error(error, - "%s.%s: ", - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_MPTCP_FLAGS); - return FALSE; - } if (NM_FLAGS_ALL(priv->mptcp_flags, NM_MPTCP_FLAGS_SIGNAL | NM_MPTCP_FLAGS_FULLMESH)) { g_set_error_literal(error, NM_CONNECTION_ERROR, @@ -1426,8 +1413,7 @@ after_interface_name: NM_SETTING_CONNECTION_MPTCP_FLAGS); return FALSE; } - f = NM_FLAGS_UNSET(priv->mptcp_flags, NM_MPTCP_FLAGS_ENABLED_ON_GLOBAL_IFACE) - | ((guint32) NM_MPTCP_FLAGS_ENABLED); + f = priv->mptcp_flags | ((guint32) NM_MPTCP_FLAGS_ENABLED); if (f != nm_mptcp_flags_normalize(f)) { g_set_error(error, NM_CONNECTION_ERROR, @@ -2608,21 +2594,30 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * If "disabled" (0x1), MPTCP handling for the interface is disabled and * no endpoints are registered. * - * The flag "enabled-on-global-iface" (0x2) means that MPTCP handling is enabled - * if the interface configures a default route in the main routing table. - * This choice is per-address family, for example if there is an IPv4 default route - * 0.0.0.0/0, IPv4 endpoints are configured. - * - * The "enabled" (0x4) flag means that MPTCP handling is explicitly enabled. + * The "enabled" (0x2) flag means that MPTCP handling is enabled. * This flag can also be implied from the presence of other flags. * - * If MPTCP handling is enabled, then endpoints will be configured - * with the specified address flags "signal" (0x10), "subflow" (0x20), "backup" (0x40), + * Even when enabled, MPTCP handling will by default still be disabled + * unless "/proc/sys/net/mptcp/enabled" sysctl is on. NetworkManager + * does not change the sysctl and this is up to the administrator + * or distribution. To configure endpoints even if the sysctl is + * disabled, "also-without-sysctl" (0x4) flag can be used. In that case, + * NetworkManager doesn't look at the sysctl and configures endpoints + * regardless. + * + * Even when enabled, NetworkManager will only configure MPTCP endpoints + * for a certain address family, if there is a unicast default route (0.0.0.0/0 + * or ::/0) in the main routing table. The flag "also-without-default-route" + * (0x8) can override that. + * + * When MPTCP handling is enabled then endpoints are configured with + * the specified address flags "signal" (0x10), "subflow" (0x20), "backup" (0x40), * "fullmesh" (0x80). See ip-mptcp(8) manual for additional information about the flags. * - * If the flags are zero, the global connection default from NetworkManager.conf is - * honored. If still unspecified, the fallback is either "disabled" or - * "enabled-on-global-iface,subflow" depending on "/proc/sys/net/mptcp/enabled". + * If the flags are zero (0x0), the global connection default from NetworkManager.conf is + * honored. If still unspecified, the fallback is "enabled,subflow". + * Note that this means that MPTCP is by default done depending on the + * "/proc/sys/net/mptcp/enabled" sysctl. * * NetworkManager does not change the MPTCP limits nor enable MPTCP via * "/proc/sys/net/mptcp/enabled". That is a host configuration which the diff --git a/src/libnm-core-public/nm-dbus-interface.h b/src/libnm-core-public/nm-dbus-interface.h index a980f5aaa9..4557dde0fb 100644 --- a/src/libnm-core-public/nm-dbus-interface.h +++ b/src/libnm-core-public/nm-dbus-interface.h @@ -1319,12 +1319,25 @@ typedef enum /*< flags >*/ { * NMMptcpFlags: * @NM_MPTCP_FLAGS_NONE: The default, meaning that no MPTCP flags are set. * @NM_MPTCP_FLAGS_DISABLED: don't configure MPTCP endpoints on the device. - * @NM_MPTCP_FLAGS_ENABLED_ON_GLOBAL_IFACE: MPTCP handling is enabled - * or disabled depending on whether a /0 default route (either IPv4 or IPv6) is - * configured in the main routing table. * @NM_MPTCP_FLAGS_ENABLED: MPTCP is enabled and endpoints will be configured. * This flag is implied if any of the other flags indicate that * MPTCP is enabled and therefore in most cases unnecessary. + * Note that if "/proc/sys/net/mptcp/enabled" sysctl is disabled, MPTCP + * handling is disabled despite this flag. This can be overruled with the + * "also-without-sysctl" flag. + * Note that by default interfaces that don't have a default route are + * excluded from having MPTCP endpoints configured. This can be overruled + * with the "also-without-default-route" and this affects endpoints + * per address family. + * @NM_MPTCP_FLAGS_ALSO_WITHOUT_SYSCTL: even if MPTCP handling is enabled + * via the "enabled" flag, it is ignored unless "/proc/sys/net/mptcp/enabled" + * is on. With this flag, MPTCP endpoints will be configured regardless + * of the sysctl setting. + * @NM_MPTCP_FLAGS_ALSO_WITHOUT_DEFAULT_ROUTE: even if MPTCP handling is enabled + * via the "enabled" flag, it is ignored per-address family unless NetworkManager + * configures a default route. With this flag, NetworkManager will also configure + * MPTCP endpoints if there is no default route. This takes effect per-address + * family. * @NM_MPTCP_FLAGS_SIGNAL: Flag for the MPTCP endpoint. The endpoint will be * announced/signaled to each peer via an MPTCP ADD_ADDR sub-option. * @NM_MPTCP_FLAGS_SUBFLOW: Flag for the MPTCP endpoint. If additional subflow creation @@ -1350,9 +1363,11 @@ typedef enum /*< flags >*/ { typedef enum /*< flags >*/ { NM_MPTCP_FLAGS_NONE = 0, - NM_MPTCP_FLAGS_DISABLED = 0x1, - NM_MPTCP_FLAGS_ENABLED_ON_GLOBAL_IFACE = 0x2, - NM_MPTCP_FLAGS_ENABLED = 0x4, + NM_MPTCP_FLAGS_DISABLED = 0x1, + NM_MPTCP_FLAGS_ENABLED = 0x2, + + NM_MPTCP_FLAGS_ALSO_WITHOUT_SYSCTL = 0x4, + NM_MPTCP_FLAGS_ALSO_WITHOUT_DEFAULT_ROUTE = 0x8, NM_MPTCP_FLAGS_SIGNAL = 0x10, NM_MPTCP_FLAGS_SUBFLOW = 0x20, diff --git a/src/libnmc-setting/settings-docs.h.in b/src/libnmc-setting/settings-docs.h.in index 2a2ec2eea2..1ed2f13419 100644 --- a/src/libnmc-setting/settings-docs.h.in +++ b/src/libnmc-setting/settings-docs.h.in @@ -14,7 +14,7 @@ #define DESCRIBE_DOC_NM_SETTING_CONNECTION_MASTER N_("Interface name of the master device or UUID of the master connection.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_MDNS N_("Whether mDNS is enabled for the connection. The permitted values are: \"yes\" (2) register hostname and resolving for the connection, \"no\" (0) disable mDNS for the interface, \"resolve\" (1) do not register hostname but allow resolving of mDNS host names and \"default\" (-1) to allow lookup of a global default in NetworkManager.conf. If unspecified, \"default\" ultimately depends on the DNS plugin (which for systemd-resolved currently means \"no\"). This feature requires a plugin which supports mDNS. Otherwise, the setting has no effect. One such plugin is dns-systemd-resolved.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_METERED N_("Whether the connection is metered. When updating this property on a currently activated connection, the change takes effect immediately.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_MPTCP_FLAGS N_("Whether to configure MPTCP endpoints and the address flags. If MPTCP is enabled in NetworkManager, it will configure the addresses of the interface as MPTCP endpoints. Note that IPv4 loopback addresses (127.0.0.0/8), IPv4 link local addresses (169.254.0.0/16), the IPv6 loopback address (::1), IPv6 link local addresses (fe80::/10), IPv6 unique local addresses (ULA, fc00::/7) and IPv6 privacy extension addresses (rfc3041, ipv6.ip6-privacy) will be excluded from being configured as endpoints. If \"disabled\" (0x1), MPTCP handling for the interface is disabled and no endpoints are registered. The flag \"enabled-on-global-iface\" (0x2) means that MPTCP handling is enabled if the interface configures a default route in the main routing table. This choice is per-address family, for example if there is an IPv4 default route 0.0.0.0/0, IPv4 endpoints are configured. The \"enabled\" (0x4) flag means that MPTCP handling is explicitly enabled. This flag can also be implied from the presence of other flags. If MPTCP handling is enabled, then endpoints will be configured with the specified address flags \"signal\" (0x10), \"subflow\" (0x20), \"backup\" (0x40), \"fullmesh\" (0x80). See ip-mptcp(8) manual for additional information about the flags. If the flags are zero, the global connection default from NetworkManager.conf is honored. If still unspecified, the fallback is either \"disabled\" or \"enabled-on-global-iface,subflow\" depending on \"/proc/sys/net/mptcp/enabled\". NetworkManager does not change the MPTCP limits nor enable MPTCP via \"/proc/sys/net/mptcp/enabled\". That is a host configuration which the admin can change via sysctl and ip-mptcp. Strict reverse path filtering (rp_filter) breaks many MPTCP use cases, so when MPTCP handling for IPv4 addresses on the interface is enabled, NetworkManager would loosen the strict reverse path filtering (1) to the loose setting (2).") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_MPTCP_FLAGS N_("Whether to configure MPTCP endpoints and the address flags. If MPTCP is enabled in NetworkManager, it will configure the addresses of the interface as MPTCP endpoints. Note that IPv4 loopback addresses (127.0.0.0/8), IPv4 link local addresses (169.254.0.0/16), the IPv6 loopback address (::1), IPv6 link local addresses (fe80::/10), IPv6 unique local addresses (ULA, fc00::/7) and IPv6 privacy extension addresses (rfc3041, ipv6.ip6-privacy) will be excluded from being configured as endpoints. If \"disabled\" (0x1), MPTCP handling for the interface is disabled and no endpoints are registered. The \"enabled\" (0x2) flag means that MPTCP handling is enabled. This flag can also be implied from the presence of other flags. Even when enabled, MPTCP handling will by default still be disabled unless \"/proc/sys/net/mptcp/enabled\" sysctl is on. NetworkManager does not change the sysctl and this is up to the administrator or distribution. To configure endpoints even if the sysctl is disabled, \"also-without-sysctl\" (0x4) flag can be used. In that case, NetworkManager doesn't look at the sysctl and configures endpoints regardless. Even when enabled, NetworkManager will only configure MPTCP endpoints for a certain address family, if there is a unicast default route (0.0.0.0/0 or ::/0) in the main routing table. The flag \"also-without-default-route\" (0x8) can override that. When MPTCP handling is enabled then endpoints are configured with the specified address flags \"signal\" (0x10), \"subflow\" (0x20), \"backup\" (0x40), \"fullmesh\" (0x80). See ip-mptcp(8) manual for additional information about the flags. If the flags are zero (0x0), the global connection default from NetworkManager.conf is honored. If still unspecified, the fallback is \"enabled,subflow\". Note that this means that MPTCP is by default done depending on the \"/proc/sys/net/mptcp/enabled\" sysctl. NetworkManager does not change the MPTCP limits nor enable MPTCP via \"/proc/sys/net/mptcp/enabled\". That is a host configuration which the admin can change via sysctl and ip-mptcp. Strict reverse path filtering (rp_filter) breaks many MPTCP use cases, so when MPTCP handling for IPv4 addresses on the interface is enabled, NetworkManager would loosen the strict reverse path filtering (1) to the loose setting (2).") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_MUD_URL N_("If configured, set to a Manufacturer Usage Description (MUD) URL that points to manufacturer-recommended network policies for IoT devices. It is transmitted as a DHCPv4 or DHCPv6 option. The value must be a valid URL starting with \"https://\". The special value \"none\" is allowed to indicate that no MUD URL is used. If the per-profile value is unspecified (the default), a global connection default gets consulted. If still unspecified, the ultimate default is \"none\".") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_MULTI_CONNECT N_("Specifies whether the profile can be active multiple times at a particular moment. The value is of type NMConnectionMultiConnect.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_PERMISSIONS N_("An array of strings defining what access a given user has to this connection. If this is NULL or empty, all users are allowed to access this connection; otherwise users are allowed if and only if they are in this list. When this is not empty, the connection can be active only when one of the specified users is logged into an active session. Each entry is of the form \"[type]:[id]:[reserved]\"; for example, \"user:dcbw:blah\". At this time only the \"user\" [type] is allowed. Any other values are ignored and reserved for future use. [id] is the username that this permission refers to, which may not contain the \":\" character. Any [reserved] information present must be ignored and is reserved for future use. All of [type], [id], and [reserved] must be valid UTF-8.") diff --git a/src/nmcli/generate-docs-nm-settings-nmcli.xml.in b/src/nmcli/generate-docs-nm-settings-nmcli.xml.in index e203316ebf..371081b0e0 100644 --- a/src/nmcli/generate-docs-nm-settings-nmcli.xml.in +++ b/src/nmcli/generate-docs-nm-settings-nmcli.xml.in @@ -420,7 +420,7 @@ + description="Whether to configure MPTCP endpoints and the address flags. If MPTCP is enabled in NetworkManager, it will configure the addresses of the interface as MPTCP endpoints. Note that IPv4 loopback addresses (127.0.0.0/8), IPv4 link local addresses (169.254.0.0/16), the IPv6 loopback address (::1), IPv6 link local addresses (fe80::/10), IPv6 unique local addresses (ULA, fc00::/7) and IPv6 privacy extension addresses (rfc3041, ipv6.ip6-privacy) will be excluded from being configured as endpoints. If "disabled" (0x1), MPTCP handling for the interface is disabled and no endpoints are registered. The "enabled" (0x2) flag means that MPTCP handling is enabled. This flag can also be implied from the presence of other flags. Even when enabled, MPTCP handling will by default still be disabled unless "/proc/sys/net/mptcp/enabled" sysctl is on. NetworkManager does not change the sysctl and this is up to the administrator or distribution. To configure endpoints even if the sysctl is disabled, "also-without-sysctl" (0x4) flag can be used. In that case, NetworkManager doesn't look at the sysctl and configures endpoints regardless. Even when enabled, NetworkManager will only configure MPTCP endpoints for a certain address family, if there is a unicast default route (0.0.0.0/0 or ::/0) in the main routing table. The flag "also-without-default-route" (0x8) can override that. When MPTCP handling is enabled then endpoints are configured with the specified address flags "signal" (0x10), "subflow" (0x20), "backup" (0x40), "fullmesh" (0x80). See ip-mptcp(8) manual for additional information about the flags. If the flags are zero (0x0), the global connection default from NetworkManager.conf is honored. If still unspecified, the fallback is "enabled,subflow". Note that this means that MPTCP is by default done depending on the "/proc/sys/net/mptcp/enabled" sysctl. NetworkManager does not change the MPTCP limits nor enable MPTCP via "/proc/sys/net/mptcp/enabled". That is a host configuration which the admin can change via sysctl and ip-mptcp. Strict reverse path filtering (rp_filter) breaks many MPTCP use cases, so when MPTCP handling for IPv4 addresses on the interface is enabled, NetworkManager would loosen the strict reverse path filtering (1) to the loose setting (2)." /> Date: Thu, 25 Aug 2022 23:07:44 +0200 Subject: glib-aux: fix nicks for zero flag in nm_utils_enum_to_str() nm_utils_enum_to_str() can print flags, that is, combinations of powers of two integers. It also supports nicks, for certain flags. When we have a nick for value zero, then that requires special handling. Otherwise, that zero nick will always show up in the string representation, although, it should only be used if the enum value is exactly zero. --- src/libnm-core-impl/tests/test-general.c | 9 +++++++++ src/libnm-glib-aux/nm-enum-utils.c | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c index 19d3271944..bcf86917e8 100644 --- a/src/libnm-core-impl/tests/test-general.c +++ b/src/libnm-core-impl/tests/test-general.c @@ -9123,6 +9123,10 @@ test_nm_utils_enum(void) .nick = "nick-5", .value = 5, }, + { + .nick = "nick-0", + .value = 0, + }, { .nick = "nick-red", .value = NM_TEST_GENERAL_COLOR_FLAGS_RED, @@ -9170,6 +9174,11 @@ test_nm_utils_enum(void) "nick-5, green", color_value_infos); + _test_nm_utils_enum_to_str_do_full(color_flags, + 0, + "nick-0", + color_value_infos); + _test_nm_utils_enum_from_str_do(bool_enum, "", FALSE, 0, NULL); _test_nm_utils_enum_from_str_do(bool_enum, " ", FALSE, 0, NULL); _test_nm_utils_enum_from_str_do(bool_enum, "invalid", FALSE, 0, "invalid"); diff --git a/src/libnm-glib-aux/nm-enum-utils.c b/src/libnm-glib-aux/nm-enum-utils.c index b7f7a3f6cc..2593a9cdfd 100644 --- a/src/libnm-glib-aux/nm-enum-utils.c +++ b/src/libnm-glib-aux/nm-enum-utils.c @@ -136,7 +136,8 @@ _nm_utils_enum_to_str_full(GType type, else return g_strdup(enum_value->value_nick); } else if (G_IS_FLAGS_CLASS(klass)) { - unsigned uvalue = (unsigned) value; + unsigned uvalue = (unsigned) value; + gboolean uvalue_was_zero = (uvalue == 0); GFlagsValue *flags_value; NMStrBuf strbuf; @@ -147,6 +148,9 @@ _nm_utils_enum_to_str_full(GType type, for (; value_infos && value_infos->nick; value_infos++) { nm_assert(_enum_is_valid_flags_nick(value_infos->nick)); + if (value_infos->value == 0 && !uvalue_was_zero) + continue; + if (uvalue == 0) { if (value_infos->value != 0) continue; -- cgit v1.2.1 From c183f10f65de3a839a1ce58a15946586ab8a6f7f Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Thu, 25 Aug 2022 15:52:27 +0200 Subject: device: wait for carrier on unavailable device even when it gets a connection assumed The test in question leaves the device with a master set, which caused a connection to get assumed and therefore the previous fix didn't kick in. Fixes-test: @restart_L2_only_lacp Fixes: 5b7f8f3f7051 ('device: wait for carrier even if it wasn't us who brought the device IFF_UP') https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1348 --- src/core/devices/nm-device.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index aa7481c71e..6980844635 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -15787,6 +15787,13 @@ _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, if (priv->sys_iface_state == NM_DEVICE_SYS_IFACE_STATE_MANAGED) ip6_managed_setup(self); device_init_static_sriov_num_vfs(self); + + /* We didn't bring the device up and we have little idea + * when was it brought up. Play it safe and assume it could + * have been brought up very recently and it might one of + * those who take time to detect carrier. + */ + carrier_detect_wait(self); } if (priv->sys_iface_state == NM_DEVICE_SYS_IFACE_STATE_MANAGED) { @@ -15794,13 +15801,6 @@ _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, if (!nm_device_bring_up(self, TRUE, &no_firmware) && no_firmware) _LOGW(LOGD_PLATFORM, "firmware may be missing."); nm_device_set_firmware_missing(self, no_firmware ? TRUE : FALSE); - } else { - /* We didn't bring the device up and we have little idea - * when was it brought up. Play it safe and assume it could - * have been brought up very recently and it might one of - * those who take time to detect carrier. - */ - carrier_detect_wait(self); } /* Ensure the device gets deactivated in response to stuff like -- cgit v1.2.1 From 6cd69fde339cc69717671226e06156339de71314 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 24 Aug 2022 16:50:14 +0200 Subject: core: log when dynamic IP configuration is restarted and why --- src/core/devices/nm-device-ethernet.c | 2 +- src/core/devices/nm-device.c | 10 ++++++---- src/core/devices/nm-device.h | 2 +- src/core/devices/wifi/nm-device-wifi.c | 4 ++-- src/core/nm-manager.c | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/core/devices/nm-device-ethernet.c b/src/core/devices/nm-device-ethernet.c index 32f2fbf9b4..40c6d208e1 100644 --- a/src/core/devices/nm-device-ethernet.c +++ b/src/core/devices/nm-device-ethernet.c @@ -451,7 +451,7 @@ supplicant_auth_state_changed(NMSupplicantInterface *iface, if (state == NM_SUPPLICANT_AUTH_STATE_SUCCESS) { nm_clear_g_signal_handler(priv->supplicant.iface, &priv->supplicant.iface_state_id); - nm_device_update_dynamic_ip_setup(NM_DEVICE(self)); + nm_device_update_dynamic_ip_setup(NM_DEVICE(self), "supplicant auth state changed"); } } diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 6980844635..44f799f4a8 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -6332,7 +6332,7 @@ _dev_unmanaged_check_external_down(NMDevice *self, gboolean only_if_unmanaged, g } void -nm_device_update_dynamic_ip_setup(NMDevice *self) +nm_device_update_dynamic_ip_setup(NMDevice *self, const char *reason) { NMDevicePrivate *priv; @@ -6343,6 +6343,8 @@ nm_device_update_dynamic_ip_setup(NMDevice *self) if (priv->state < NM_DEVICE_STATE_IP_CONFIG || priv->state > NM_DEVICE_STATE_ACTIVATED) return; + _LOGD(LOGD_DEVICE, "restarting dynamic IP configuration (%s)", reason); + g_hash_table_remove_all(priv->ip6_saved_properties); if (priv->ipdhcp_data_4.state != NM_DEVICE_IP_STATE_NONE) @@ -6742,7 +6744,7 @@ device_link_changed(gpointer user_data) /* Update DHCP, etc, if needed */ if (ip_ifname_changed) - nm_device_update_dynamic_ip_setup(self); + nm_device_update_dynamic_ip_setup(self, "IP interface changed"); was_up = priv->up; priv->up = NM_FLAGS_HAS(pllink->n_ifi_flags, IFF_UP); @@ -6802,7 +6804,7 @@ device_link_changed(gpointer user_data) * renew DHCP leases and such. */ if (priv->state == NM_DEVICE_STATE_ACTIVATED) { - nm_device_update_dynamic_ip_setup(self); + nm_device_update_dynamic_ip_setup(self, "interface got carrier"); } } @@ -6864,7 +6866,7 @@ device_ip_link_changed(gpointer user_data) priv->ip_iface_ = g_strdup(ip_iface); update_prop_ip_iface(self); - nm_device_update_dynamic_ip_setup(self); + nm_device_update_dynamic_ip_setup(self, "interface renamed"); } return G_SOURCE_REMOVE; diff --git a/src/core/devices/nm-device.h b/src/core/devices/nm-device.h index 382c866053..de850e68f2 100644 --- a/src/core/devices/nm-device.h +++ b/src/core/devices/nm-device.h @@ -764,7 +764,7 @@ void nm_device_update_metered(NMDevice *self); gboolean nm_device_update_hw_address(NMDevice *self); void nm_device_update_initial_hw_address(NMDevice *self); void nm_device_update_permanent_hw_address(NMDevice *self, gboolean force_freeze); -void nm_device_update_dynamic_ip_setup(NMDevice *self); +void nm_device_update_dynamic_ip_setup(NMDevice *self, const char *reason); guint nm_device_get_supplicant_timeout(NMDevice *self); gboolean nm_device_auth_retries_try_next(NMDevice *self); diff --git a/src/core/devices/wifi/nm-device-wifi.c b/src/core/devices/wifi/nm-device-wifi.c index 39c68d777f..43798b85ad 100644 --- a/src/core/devices/wifi/nm-device-wifi.c +++ b/src/core/devices/wifi/nm-device-wifi.c @@ -2520,7 +2520,7 @@ supplicant_iface_state(NMDeviceWifi *self, _LOGD(LOGD_WIFI, "supplicant state settled after roaming, renew dynamic IP configuration"); nm_clear_g_source_inst(&priv->roam_supplicant_wait_source); - nm_device_update_dynamic_ip_setup(device); + nm_device_update_dynamic_ip_setup(device, "roamed to a different AP"); } } break; @@ -2663,7 +2663,7 @@ supplicant_iface_notify_current_bss(NMSupplicantInterface *iface, if (nm_supplicant_interface_get_state(priv->sup_iface) == NM_SUPPLICANT_INTERFACE_STATE_COMPLETED) { - nm_device_update_dynamic_ip_setup(NM_DEVICE(self)); + nm_device_update_dynamic_ip_setup(NM_DEVICE(self), "roamed to a different AP"); } else { /* Wait that the authentication to new the AP completes before * trying to renew, otherwise the DHCP REQUEST could be lost diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index 3af24aa00b..822df7ad3b 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -6580,7 +6580,7 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed) && !nm_device_get_unmanaged_flags(device, NM_UNMANAGED_SLEEPING)) { /* DHCP leases of software devices could have gone stale * so we need to renew them. */ - nm_device_update_dynamic_ip_setup(device); + nm_device_update_dynamic_ip_setup(device, "wake up"); continue; } -- cgit v1.2.1 From 905adabdba033bbfc33013d0ad203bd444131dc5 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 24 Aug 2022 16:52:52 +0200 Subject: device: restart DHCP when the MAC changes If the MAC changes there is the possibility that the DHCP client will not be able to renew the address because it uses the old MAC as CHADDR. Depending on the implementation, the DHCP server might use CHADDR (so, the old address) as the destination MAC for DHCP replies, and those packets will be lost. To avoid this problem, restart the DHCP client when the MAC changes. https://bugzilla.redhat.com/show_bug.cgi?id=2110000 --- src/core/devices/nm-device.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 44f799f4a8..1df99a82ee 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -6646,6 +6646,7 @@ device_link_changed(gpointer user_data) NMDeviceClass *klass = NM_DEVICE_GET_CLASS(self); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); gboolean ip_ifname_changed = FALSE; + gboolean hw_addr_changed; nm_auto_nmpobj const NMPObject *pllink_keep_alive = NULL; const NMPlatformLink *pllink; const char *str; @@ -6692,9 +6693,9 @@ device_link_changed(gpointer user_data) if (ifindex == nm_device_get_ip_ifindex(self)) _stats_update_counters_from_pllink(self, pllink); - had_hw_addr = (priv->hw_addr != NULL); - nm_device_update_hw_address(self); - got_hw_addr = (!had_hw_addr && priv->hw_addr); + had_hw_addr = (priv->hw_addr != NULL); + hw_addr_changed = nm_device_update_hw_address(self); + got_hw_addr = (!had_hw_addr && priv->hw_addr); nm_device_update_permanent_hw_address(self, FALSE); if (pllink->name[0] && !nm_streq(priv->iface, pllink->name)) { @@ -6745,6 +6746,8 @@ device_link_changed(gpointer user_data) /* Update DHCP, etc, if needed */ if (ip_ifname_changed) nm_device_update_dynamic_ip_setup(self, "IP interface changed"); + else if (hw_addr_changed) + nm_device_update_dynamic_ip_setup(self, "hw-address changed"); was_up = priv->up; priv->up = NM_FLAGS_HAS(pllink->n_ifi_flags, IFF_UP); -- cgit v1.2.1 From befbad7375c2c1f4b45d4427cf257abf5d805d40 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 25 Aug 2022 23:27:29 +0200 Subject: style: fix code formatting Fixes: eec9efd98950 ('glib-aux: fix nicks for zero flag in nm_utils_enum_to_str()') --- src/libnm-core-impl/tests/test-general.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c index bcf86917e8..1eda17c7a7 100644 --- a/src/libnm-core-impl/tests/test-general.c +++ b/src/libnm-core-impl/tests/test-general.c @@ -9174,10 +9174,7 @@ test_nm_utils_enum(void) "nick-5, green", color_value_infos); - _test_nm_utils_enum_to_str_do_full(color_flags, - 0, - "nick-0", - color_value_infos); + _test_nm_utils_enum_to_str_do_full(color_flags, 0, "nick-0", color_value_infos); _test_nm_utils_enum_from_str_do(bool_enum, "", FALSE, 0, NULL); _test_nm_utils_enum_from_str_do(bool_enum, " ", FALSE, 0, NULL); -- cgit v1.2.1 From 9902373c6d984f3a72a6dc5f0b6ea1cf3a09f18d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 26 Aug 2022 00:00:01 +0200 Subject: tests: fix "test-client.py" for early python3 versions ModuleNotFoundError was only introduced in later python 3 versions. Use just "ImportError", which is the parent class anyway. Fixes: f7e484c8eda4 ('tests: fix "test-client.py" ignoring missing "NM" module') --- src/tests/client/test-client.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/tests/client/test-client.py b/src/tests/client/test-client.py index 68cc08e86d..85a09ad25c 100755 --- a/src/tests/client/test-client.py +++ b/src/tests/client/test-client.py @@ -111,8 +111,6 @@ import dbus.service import dbus.mainloop.glib import io -moduleNotFoundError = ModuleNotFoundError if sys.version_info[0] >= 3 else ImportError - import gi try: @@ -132,7 +130,7 @@ else: try: import pexpect -except moduleNotFoundError: +except ImportError: pexpect = None -- cgit v1.2.1 From 1ece234b2437faef419981ada05b82ab6ac59532 Mon Sep 17 00:00:00 2001 From: Ana Cabral Date: Fri, 26 Aug 2022 16:26:18 +0200 Subject: NEWS: update --- NEWS | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index fb248aecb5..8282b0fe0f 100644 --- a/NEWS +++ b/NEWS @@ -3,11 +3,6 @@ NetworkManager-1.40 Overview of changes since NetworkManager-1.38 ============================================= -This is a snapshot of NetworkManager development. The API is -subject to change and not guaranteed to be compatible with -the later release. -USE AT YOUR OWN RISK. NOT RECOMMENDED FOR PRODUCTION USE! - * Drop unused, internal systemd DHCPv4 client. This is long replaced by nettools' n-dhcp4 implementation. * The nmcli command now supports --offline argument with "add" and @@ -44,6 +39,9 @@ USE AT YOUR OWN RISK. NOT RECOMMENDED FOR PRODUCTION USE! * Improve the reapply of non-bridge properties. * Honor adding a Bluetooth NAP connection with all available methods. * Improve carrier detection. +* During the build, stop relying on intltool for i18n and use gettext only. +* Undeprecate nm_remote_connection_get_secrets() in libnm. +* NetworkManager now will restart DHCP if the MAC changes on a device. * Several internal improvements. The following changes were backported to 1.38.x releases between 1.38.0 -- cgit v1.2.1