@@ -100,7 +100,10 @@ type_str(const NetplanNetDefinition* def)
100100 g_assert (def -> backend_settings .passthrough != NULL );
101101 GHashTable * passthrough = def -> backend_settings .passthrough ;
102102 GHashTable * connection = g_hash_table_lookup (passthrough , "connection" );
103- return g_hash_table_lookup (connection , "type" );
103+ if (connection ) {
104+ return g_hash_table_lookup (connection , "type" );
105+ }
106+ return NULL ;
104107 // LCOV_EXCL_START
105108 default :
106109 g_assert_not_reached ();
@@ -634,6 +637,12 @@ write_nm_conf_access_point(const NetplanNetDefinition* def, const char* rootdir,
634637 else
635638 g_assert (ap == NULL );
636639
640+ nm_type = type_str (def );
641+ if (def -> type == NETPLAN_DEF_TYPE_NM && nm_type == NULL ) {
642+ g_set_error (error , NETPLAN_BACKEND_ERROR , NETPLAN_ERROR_UNSUPPORTED , "ERROR: %s: NetworkManager connection type undefined\n" , def -> id );
643+ return FALSE;
644+ }
645+
637646 if (def -> type == NETPLAN_DEF_TYPE_VLAN && def -> sriov_vlan_filter ) {
638647 g_debug ("%s is defined as a hardware SR-IOV filtered VLAN, postponing creation" , def -> id );
639648 return TRUE;
@@ -653,7 +662,6 @@ write_nm_conf_access_point(const NetplanNetDefinition* def, const char* rootdir,
653662 g_key_file_set_string (kf , "connection" , "id" , nd_nm_id );
654663 }
655664
656- nm_type = type_str (def );
657665 if (nm_type && def -> type != NETPLAN_DEF_TYPE_NM )
658666 g_key_file_set_string (kf , "connection" , "type" , nm_type );
659667
@@ -1082,11 +1090,21 @@ netplan_state_finish_nm_write(
10821090 GString * tmp = NULL ;
10831091 guint unmanaged = nd -> backend == NETPLAN_BACKEND_NM ? 0 : 1 ;
10841092
1093+ if (nd -> type == NETPLAN_DEF_TYPE_NM_PLACEHOLDER_ || nd -> backend == NETPLAN_BACKEND_OVS ) {
1094+ iter = iter -> next ;
1095+ continue ;
1096+ }
1097+
1098+ nm_type = type_str (nd );
1099+ if (nd -> type == NETPLAN_DEF_TYPE_NM && nm_type == NULL ) {
1100+ /* Will happen when errors are ignored */
1101+ iter = iter -> next ;
1102+ continue ;
1103+ }
1104+
10851105 g_autofree char * netdef_id = _netplan_scrub_string (nd -> id );
10861106 /* Special case: manage or ignore any device of given type on empty "match: {}" stanza */
10871107 if (nd -> has_match && !nd -> match .driver && !nd -> match .mac && !nd -> match .original_name ) {
1088- nm_type = type_str (nd );
1089- g_assert (nm_type != NULL );
10901108 g_string_append_printf (nm_conf , "[device-netplan.%s.%s]\nmatch-device=type:%s\n"
10911109 "managed=%d\n\n" , netplan_def_type_name (nd -> type ),
10921110 netdef_id , nm_type , !unmanaged );
0 commit comments