summaryrefslogtreecommitdiff
path: root/libnm-util/nm-setting-bond.c
blob: 39e1494de3237e2182fd3fbb96ae86539ea53498 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */

/*
 * Thomas Graf <tgraf@redhat.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 * (C) Copyright 2011 - 2013 Red Hat, Inc.
 */

#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <dbus/dbus-glib.h>
#include <glib/gi18n.h>

#include "nm-setting-bond.h"
#include "nm-param-spec-specialized.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-dbus-glib-types.h"
#include "nm-glib-compat.h"
#include "nm-setting-private.h"

/**
 * SECTION:nm-setting-bond
 * @short_description: Describes connection properties for bonds
 * @include: nm-setting-bond.h
 *
 * The #NMSettingBond object is a #NMSetting subclass that describes properties
 * necessary for bond connections.
 **/

/**
 * nm_setting_bond_error_quark:
 *
 * Registers an error quark for #NMSettingBond if necessary.
 *
 * Returns: the error quark used for #NMSettingBond errors.
 **/
GQuark
nm_setting_bond_error_quark (void)
{
	static GQuark quark;

	if (G_UNLIKELY (!quark))
		quark = g_quark_from_static_string ("nm-setting-bond-error-quark");
	return quark;
}


G_DEFINE_TYPE_WITH_CODE (NMSettingBond, nm_setting_bond, NM_TYPE_SETTING,
                         _nm_register_setting (NM_SETTING_BOND_SETTING_NAME,
                                               g_define_type_id,
                                               1,
                                               NM_SETTING_BOND_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BOND)

#define NM_SETTING_BOND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BOND, NMSettingBondPrivate))

typedef struct {
	char *interface_name;

	char *mode;
	int miimon;
	int downdelay;
	int updelay;
	int arp_interval;
	char **arp_ip_target;
	char *arp_validate;
	char *primary;
	char *primary_reselect;
	char *fail_over_mac;
	int use_carrier;
	char *ad_select;
	char *xmit_hash_policy;
	int resend_igmp;

	GHashTable *options;
} NMSettingBondPrivate;

enum {
	PROP_0,
	PROP_INTERFACE_NAME,

	PROP_MODE,
	PROP_MIIMON,
	PROP_DOWNDELAY,
	PROP_UPDELAY,
	PROP_ARP_INTERVAL,
	PROP_ARP_IP_TARGET,
	PROP_ARP_VALIDATE,
	PROP_PRIMARY,
	PROP_PRIMARY_RESELECT,
	PROP_FAIL_OVER_MAC,
	PROP_USE_CARRIER,
	PROP_AD_SELECT,
	PROP_XMIT_HASH_POLICY,
	PROP_RESEND_IGMP,

	PROP_OPTIONS,
	LAST_PROP
};
#define _FIRST_KERNEL_PROP PROP_MODE
#define _LAST_KERNEL_PROP PROP_RESEND_IGMP

enum {
	TYPE_NONE, /* must be 0, so that it is the default in props if not explicitly set. */
	TYPE_INT,
	TYPE_STR,
	TYPE_BOTH,
	TYPE_IP,
	TYPE_IFNAME,
};

typedef struct {
	guint opt_type;
	const char *kernel_name;
	const char *list[7];
	const char *list_sentinel[1]; /* dummy, to NULL terminate the previous 'list' array */
	GParamSpec *pspec;
	char *defval;
} BondProperty;

static BondProperty props[LAST_PROP] = {
	/* specifying the kernel name is only necessary, when it differs from the property name. */

	[PROP_MODE]             = { TYPE_BOTH,   NULL,
	                            { "balance-rr", "active-backup", "balance-xor", "broadcast", "802.3ad", "balance-tlb", "balance-alb" } },
	[PROP_MIIMON]           = { TYPE_INT },
	[PROP_DOWNDELAY]        = { TYPE_INT },
	[PROP_UPDELAY]          = { TYPE_INT },
	[PROP_ARP_INTERVAL]     = { TYPE_INT,    NM_SETTING_BOND_OPTION_ARP_INTERVAL },
	[PROP_ARP_IP_TARGET]    = { TYPE_IP,     NM_SETTING_BOND_OPTION_ARP_IP_TARGET },
	[PROP_ARP_VALIDATE]     = { TYPE_BOTH,   NM_SETTING_BOND_OPTION_ARP_VALIDATE,
	                            { "none", "active", "backup", "all" } },
	[PROP_PRIMARY]          = { TYPE_IFNAME },
	[PROP_PRIMARY_RESELECT] = { TYPE_BOTH,   NM_SETTING_BOND_OPTION_PRIMARY_RESELECT,
	                            { "always", "better", "failure" } },
	[PROP_FAIL_OVER_MAC]    = { TYPE_BOTH,   NM_SETTING_BOND_OPTION_FAIL_OVER_MAC,
	                            { "none", "active", "follow" } },
	[PROP_USE_CARRIER]      = { TYPE_INT,    NM_SETTING_BOND_OPTION_USE_CARRIER },
	[PROP_AD_SELECT]        = { TYPE_BOTH,   NM_SETTING_BOND_OPTION_AD_SELECT,
	                          { "stable", "bandwidth", "count" } },
	[PROP_XMIT_HASH_POLICY] = { TYPE_STR,    NM_SETTING_BOND_OPTION_XMIT_HASH_POLICY,
	                          { "layer2", "layer2+3", "layer3+4", "encap2+3", "encap3+4" } },
	[PROP_RESEND_IGMP]      = { TYPE_INT,    NM_SETTING_BOND_OPTION_RESEND_IGMP },
};

/**
 * nm_setting_bond_new:
 *
 * Creates a new #NMSettingBond object with default values.
 *
 * Returns: (transfer full): the new empty #NMSettingBond object
 **/
NMSetting *
nm_setting_bond_new (void)
{
	return (NMSetting *) g_object_new (NM_TYPE_SETTING_BOND, NULL);
}

/*****************************************************************************/

/**
 * nm_setting_bond_get_interface_name:
 * @setting: the #NMSettingBond
 *
 * Returns: the #NMSettingBond:interface-name property of the setting
 **/
const char *
nm_setting_bond_get_interface_name (const NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);

	return NM_SETTING_BOND_GET_PRIVATE (setting)->interface_name;
}

/**
 * nm_setting_bond_get_mode:
 * @setting: the #NMSettingBond
 *
 * Returns: the #NMSettingBond:mode property of the setting
 *
 * Since: 0.9.10
 **/
const char *
nm_setting_bond_get_mode (const NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);

	return NM_SETTING_BOND_GET_PRIVATE (setting)->mode;
}

/**
 * nm_setting_bond_get_miimon:
 * @setting: the #NMSettingBond
 *
 * Returns: the #NMSettingBond:miimon property of the setting
 *
 * Since: 0.9.10
 **/
guint
nm_setting_bond_get_miimon (const NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);

	return NM_SETTING_BOND_GET_PRIVATE (setting)->miimon;
}

/**
 * nm_setting_bond_get_downdelay:
 * @setting: the #NMSettingBond
 *
 * Returns: the #NMSettingBond:downdelay property of the setting
 *
 * Since: 0.9.10
 **/
guint
nm_setting_bond_get_downdelay (const NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);

	return NM_SETTING_BOND_GET_PRIVATE (setting)->downdelay;
}

/**
 * nm_setting_bond_get_updelay:
 * @setting: the #NMSettingBond
 *
 * Returns: the #NMSettingBond:updelay property of the setting
 *
 * Since: 0.9.10
 **/
guint
nm_setting_bond_get_updelay (const NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);

	return NM_SETTING_BOND_GET_PRIVATE (setting)->updelay;
}

/**
 * nm_setting_bond_get_arp_interval:
 * @setting: the #NMSettingBond
 *
 * Returns: the #NMSettingBond:arp-interval property of the setting
 *
 * Since: 0.9.10
 **/
guint
nm_setting_bond_get_arp_interval (const NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);

	return NM_SETTING_BOND_GET_PRIVATE (setting)->arp_interval;
}

/**
 * nm_setting_bond_get_arp_ip_target:
 * @setting: the #NMSettingBond
 *
 * Returns: (transfer none): the #NMSettingBond:arp-ip-target property
 *   of the setting (which belongs to the setting and must not be freed).
 *
 * Since: 0.9.10
 **/
const char *const*
nm_setting_bond_get_arp_ip_target (const NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);

	return (const char *const*) NM_SETTING_BOND_GET_PRIVATE (setting)->arp_ip_target;
}

/**
 * nm_setting_bond_get_arp_validate:
 * @setting: the #NMSettingBond
 *
 * Returns: the #NMSettingBond:arp-validate property of the setting
 *
 * Since: 0.9.10
 **/
const char *
nm_setting_bond_get_arp_validate (const NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);

	return NM_SETTING_BOND_GET_PRIVATE (setting)->arp_validate;
}

/**
 * nm_setting_bond_get_primary:
 * @setting: the #NMSettingBond
 *
 * Returns: the #NMSettingBond:primary property of the setting
 *
 * Since: 0.9.10
 **/
const char *
nm_setting_bond_get_primary (const NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);

	return NM_SETTING_BOND_GET_PRIVATE (setting)->primary;
}

/**
 * nm_setting_bond_get_primary_reselect:
 * @setting: the #NMSettingBond
 *
 * Returns: the #NMSettingBond:primary-reselect property of the setting
 *
 * Since: 0.9.10
 **/
const char *
nm_setting_bond_get_primary_reselect (const NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);

	return NM_SETTING_BOND_GET_PRIVATE (setting)->primary_reselect;
}

/**
 * nm_setting_bond_get_fail_over_mac:
 * @setting: the #NMSettingBond
 *
 * Returns: the #NMSettingBond:fail-over-mac property of the setting
 *
 * Since: 0.9.10
 **/
const char *
nm_setting_bond_get_fail_over_mac (const NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);

	return NM_SETTING_BOND_GET_PRIVATE (setting)->fail_over_mac;
}

/**
 * nm_setting_bond_get_use_carrier:
 * @setting: the #NMSettingBond
 *
 * Returns: the #NMSettingBond:use-carrier property of the setting
 *
 * Since: 0.9.10
 **/
gboolean
nm_setting_bond_get_use_carrier (const NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);

	return NM_SETTING_BOND_GET_PRIVATE (setting)->use_carrier;
}

/**
 * nm_setting_bond_get_ad_select:
 * @setting: the #NMSettingBond
 *
 * Returns: the #NMSettingBond:ad-select property of the setting
 *
 * Since: 0.9.10
 **/
const char *
nm_setting_bond_get_ad_select (const NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);

	return NM_SETTING_BOND_GET_PRIVATE (setting)->ad_select;
}

/**
 * nm_setting_bond_get_xmit_hash_policy:
 * @setting: the #NMSettingBond
 *
 * Returns: the #NMSettingBond:xmit-hash-policy property of the setting
 *
 * Since: 0.9.10
 **/
const char *
nm_setting_bond_get_xmit_hash_policy (const NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);

	return NM_SETTING_BOND_GET_PRIVATE (setting)->xmit_hash_policy;
}

/**
 * nm_setting_bond_get_resend_igmp:
 * @setting: the #NMSettingBond
 *
 * Returns: the #NMSettingBond:resend-igmp property of the setting
 *
 * Since: 0.9.10
 **/
guint
nm_setting_bond_get_resend_igmp (const NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);

	return NM_SETTING_BOND_GET_PRIVATE (setting)->resend_igmp;
}

/*****************************************************************************/

static BondProperty *
find_property_by_pspec (const GParamSpec *pspec, guint *out_idx, gboolean kernel_only)
{
	guint i   = kernel_only ? _FIRST_KERNEL_PROP    : PROP_0 + 1;
	guint end = kernel_only ? _LAST_KERNEL_PROP + 1 : LAST_PROP;

	g_return_val_if_fail (pspec != NULL, NULL);

	for (; i < end; i++) {
		if (props[i].pspec == pspec) {
			if (out_idx)
				*out_idx = i;
			return &props[i];
		}
	}
	if (out_idx)
		*out_idx = LAST_PROP;
	return NULL;
}

/* Depending on kernel_only, find only kernel properties. */
static BondProperty *
find_property_by_name (const char *name, guint *out_idx, gboolean kernel_only)
{
	guint i   = kernel_only ? _FIRST_KERNEL_PROP    : PROP_0 + 1;
	guint end = kernel_only ? _LAST_KERNEL_PROP + 1 : LAST_PROP;

	g_return_val_if_fail (name != NULL, NULL);

	for (; i < end; i++) {
		const char *new_name = g_param_spec_get_name (props[i].pspec);

		if (strcmp (name, new_name) == 0 || g_strcmp0 (name, props[i].kernel_name) == 0) {
			if (out_idx)
				*out_idx = i;
			return &props[i];
		}
	}
	if (out_idx)
		*out_idx = LAST_PROP;
	return NULL;
}

/* For a property or kernel name, returns the property name */
static const char *
get_property_name (const BondProperty *prop)
{
	return prop ? g_param_spec_get_name (prop->pspec) : NULL;
}

/* For a property or kernel name, returns the kernel option name */
static const char *
get_kernel_name (const BondProperty *prop)
{
	if (!prop)
		return NULL;
	return prop->kernel_name ? prop->kernel_name : g_param_spec_get_name (prop->pspec);
}

static gboolean
int_from_string (const char *s, glong *out_num)
{
	long int n;
	char *end;

	if (!s)
		return FALSE;
	errno = 0;
	n = strtol (s, &end, 10);
	if (out_num)
		*out_num = n;
	return !errno && !*end;
}

static gboolean
validate_int (const BondProperty *prop, const char *value, int *out_num)
{
	GParamSpecInt *ispec;
	glong num = 0;
	gboolean success = FALSE;

	g_assert (G_IS_PARAM_SPEC_INT (prop->pspec));
	if (!int_from_string (value, &num))
		goto out;

	ispec = G_PARAM_SPEC_INT (prop->pspec);
	success = (num >= ispec->minimum && num <= ispec->maximum);
out:
	if (out_num)
		*out_num = success ? num : 0;
	return success;
}

static gboolean
validate_list (const BondProperty *prop, const char *value)
{
	const char *const*ptr;

	if (value) {
		for (ptr = prop->list; *ptr; ptr++) {
			if (strcmp (*ptr, value) == 0)
				return TRUE;
		}
	}
	return FALSE;
}

/* by making it a macro, we don't have to worry about using glong as type of idx (otherwise, we would have to check for integer overflow too. */
#define IS_VALID_LIST_INDEX(prop, idx)    ( ((idx) >= 0) && ((idx) < g_strv_length ((char **) (prop)->list)) )

static gboolean
validate_both (const BondProperty *prop, const char *value)
{
	glong num = -1;

	if (!value)
		return FALSE;

	if (validate_list (prop, value))
		return TRUE;

	if (!int_from_string (value, &num))
		return FALSE;

	/* Ensure number is within bounds of string list */
	return IS_VALID_LIST_INDEX (prop, num);
}

static char **
parse_ip (const char *value, gboolean warn_on_error)
{
	char **ips, **iter;
	struct in_addr addr;

	if (!value || !value[0]) {
		/* missing value is valid, just return NULL instead of an empty array. */
		return NULL;
	}

	/* lets be more forgiving when accepting the input string. */
	ips = g_strsplit_set (value, " ,", 0);
	for (iter = ips; *iter; iter++) {
		if (!*iter) {
			/* don't be so strict, just skip over empty values. */
			continue;
		}
		if (!inet_aton (*iter, &addr)) {
			g_strfreev (ips);
			g_return_val_if_fail (!warn_on_error, NULL);
			return NULL;
		}
	}
	return ips;
}

static gboolean
validate_ip (const char *value)
{
	char **ips;

	if (!value || !value[0]) {
		/* there is only one TYPE_IP, and that property is not mandatory.
		 * Accept empty as valid.
		 **/
		return TRUE;
	}

	/* make reuse of parse_ip, as it should validate the input anyway. */
	ips = parse_ip (value, FALSE);
	if (!ips)
		return FALSE;

	g_strfreev (ips);
	return TRUE;
}

static gboolean
validate_ifname (const char *value)
{
	if (!value || !value[0]) {
		/* there is only one TYPE_IFNAME, and that property is not mandatory.
		 * Accept empty as valid.
		 **/
		return TRUE;
	}

	return nm_utils_iface_valid_name (value);
}

/* Checks whether @value is is a valid value for @prop.
 *
 * Returns: TRUE, if the @value is valid for the given name.
 * If @value is NULL, false will be returned.
 **/
static gboolean
validate_property (const BondProperty *prop, const char *value)
{
	switch (prop->opt_type) {
	case TYPE_INT:
		return validate_int (prop, value, NULL);
	case TYPE_STR:
		return validate_list (prop, value);
	case TYPE_BOTH:
		return validate_both (prop, value);
	case TYPE_IP:
		return validate_ip (value);
	case TYPE_IFNAME:
		return validate_ifname (value);
	case TYPE_NONE:
	default:
		g_assert_not_reached();
	}
	return FALSE;
}

/*****************************************************************************/

const char *
nm_setting_bond_get_property_name (const char *name)
{
	return get_property_name (find_property_by_name (name, NULL, TRUE));
}

const char *
nm_setting_bond_get_kernel_name (const char *name)
{
	return get_kernel_name (find_property_by_name (name, NULL, TRUE));
}

const char *const*
nm_setting_bond_get_kernel_names ()
{
	static const char *array[_LAST_KERNEL_PROP - _FIRST_KERNEL_PROP + 1 + 1] = { NULL };

	/* initialize the array once */
	if (G_UNLIKELY (array[0] == NULL)) {
		guint prop, i;

		for (prop = _FIRST_KERNEL_PROP, i = 0; prop <= _LAST_KERNEL_PROP; prop++, i++)
			array[i] = get_kernel_name (&props[prop]);
	}

	return array;
}

/**
 * nm_setting_bond_get_string:
 * @setting: the #NMSettingBond
 * @name: the option name for which to retrieve the value
 *
 * Returns the value for the given name, converted to string.
 *
 * Returns: the value as string, or %NULL if the name does not
 * exist.
 **/
const char *
nm_setting_bond_get_string (const NMSettingBond *setting,
                            const char *name)
{
	NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (setting);
	const char *value;
	gboolean result;
	BondProperty *prop;

	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);

	if (!name)
		return NULL;

	result = g_hash_table_lookup_extended (priv->options, name, NULL, (void **) &value);
	if (result)
		return value;

	/* Try to lookup by property name instead of the kernel name that is used
	 * to index the options hash table... */
	prop = find_property_by_name (name, NULL, TRUE);
	if (!prop)
		return NULL;

	/* 'name' is a valid property name, but we did not find it in the options hash.
	 * Since every element *must* be in the options hash, this can only mean, that
	 * the user tried to lookup by property name for items that have a different
	 * kernel_name. Support lookup by this alias. */
	result = g_hash_table_lookup_extended (priv->options, get_kernel_name (prop), NULL, (void **) &value);
	g_assert (result);

	return value;
}

gboolean
nm_setting_bond_is_default (const NMSettingBond *setting, const char *name, GValue *default_value)
{
	GValue val = G_VALUE_INIT;
	GValue def = G_VALUE_INIT;
	BondProperty *prop;
	gboolean is_default;

	if (!NM_IS_SETTING_BOND (setting))
		goto ERROR_OUT;
	prop = find_property_by_name (name, NULL, TRUE);
	if (!prop)
		goto ERROR_OUT;

	g_value_init (&val, prop->pspec->value_type);
	g_value_init (&def, prop->pspec->value_type);

	g_object_get_property (G_OBJECT (setting), get_property_name (prop), &val);
	g_param_value_set_default (prop->pspec, &def);

	if (G_VALUE_HOLDS_INT (&val))
		is_default = g_value_get_int (&val) == g_value_get_int (&def);
	else if (G_VALUE_HOLDS_STRING (&val))
		is_default = g_strcmp0 (g_value_get_string (&val), g_value_get_string (&def)) == 0;
	else if (G_VALUE_HOLDS (&val, G_TYPE_STRV)) {
		char **v, **d;

		v = (char **) g_value_get_boxed (&val);
		d = (char **) g_value_get_boxed (&def);

		is_default = v == d;
		if (!is_default && v && d) {
			/* We know, that our only STRV type (ARP_IP_TARGET) has a default value of NULL,
			 * so don't implement any further comparison now. */
			g_assert_not_reached ();
		}
	} else
		g_assert_not_reached();

	if (default_value)
		g_value_copy (&def, default_value);

	g_value_unset (&val);
	g_value_unset (&def);

	return is_default;

ERROR_OUT:
	if (default_value)
		g_value_unset (default_value);
	g_return_val_if_fail (FALSE, FALSE);
	return FALSE;
}

/**
 * nm_setting_bond_set_string:
 * @setting: the #NMSettingBond
 * @name: name for the option
 * @value: value for the option
 *
 * Set a parameter to a value given as string. The value will be
 * converted into the proper type. If the string cannot be converted
 * the function does nothing and returns %FALSE.
 *
 * Returns: %TRUE if the option was valid and successfully set, %FALSE if it was not.
 *
 * Since: 0.9.10
 **/
gboolean
nm_setting_bond_set_string (NMSettingBond *setting,
                            const char *name,
                            const char *value)
{
	NMSettingBondPrivate *priv;
	GObject *object = G_OBJECT (setting);
	const BondProperty *prop = NULL;
	const char *prop_name;
	glong num = 0;

	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);

	priv = NM_SETTING_BOND_GET_PRIVATE (setting);

	prop = find_property_by_name (name, NULL, TRUE);
	prop_name = get_property_name (prop);
	if (!prop_name)
		return FALSE;
	if (!validate_property (prop, value))
		return FALSE;

	switch (prop->opt_type) {
	case TYPE_INT:
		if (!int_from_string (value, &num))
			g_assert_not_reached ();
		g_object_set (object, prop_name, (gint) num, NULL);
		break;
	case TYPE_BOTH: {
		const char *str_value = value;

		/* Might be an integer-as-string; find the string */
		if (int_from_string (value, &num)) {
			/* FIXME: do we really want to coerce the value? verify() currently accepts numeric values
			 * for the TYPE_BOTH items. NMDeviceBond has to cope with the ambiguity of the options
			 * names anyway. It might be better, to support the same names as the kernel does,
			 * including numeric values. Also, when reading the value from sysfs, we will also
			 * encounter numeric values (so, either we ~always~ coerce -> set_property), or not at all.
			 **/
			str_value = prop->list[num];
		}
		g_object_set (object, prop_name, str_value, NULL);
		break;
	}
	case TYPE_IFNAME:
	case TYPE_STR:
		g_object_set (object, prop_name, value, NULL);
		break;
	case TYPE_IP: {
		char **ip = parse_ip (value, TRUE);

		g_object_set (object, prop_name, ip, NULL);
		g_strfreev (ip);
		break;
	}
	case TYPE_NONE:
	default:
		g_assert_not_reached ();
		break;
	}

	return TRUE;
}

/**
 * nm_setting_bond_set_default:
 * @setting: the #NMSettingBond
 * @name: name of the option to remove
 *
 * Resets the bonding option to the default value.
 *
 * Since: 0.9.10
 **/
void
nm_setting_bond_set_default (NMSettingBond *setting,
                             const char *name)
{
	GObject *object = G_OBJECT (setting);
	NMSettingBondPrivate *priv;
	const BondProperty *prop;
	const char *prop_name;
	GValue defval = G_VALUE_INIT;

	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
	priv = NM_SETTING_BOND_GET_PRIVATE (setting);

	prop = find_property_by_name (name, NULL, TRUE);
	prop_name = get_property_name (prop);
	if (!prop_name)
		return;

	g_value_init (&defval, prop->pspec->value_type);
	g_param_value_set_default (prop->pspec, &defval);
	g_object_set_property (object, prop_name, &defval);
	g_value_unset (&defval);
}

/**
 * nm_setting_bond_validate_default:
 * @name: the name of the option
 * @value: name value to be validated.
 * @error: (out) (allow-none): The error description
 *
 * Validates a given name and value, where the value is as string.
 *
 * Since: 0.9.10
 **/
gboolean
nm_setting_bond_validate_string (const char *name, const char *value, GError **error)
{
	const BondProperty *prop = find_property_by_name (name, NULL, TRUE);

	if (!prop) {
		g_set_error_literal (error,
		                     NM_SETTING_BOND_ERROR,
		                     NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
		                     _("property is invalid"));
		g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, name);
		return FALSE;
	}

	if (!validate_property (prop, value)) {
		g_set_error (error,
		             NM_SETTING_BOND_ERROR,
		             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
		             _("'%s' is not a valid value for '%s'"),
		             value, name);
		g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, name);
		return FALSE;
	}

	return TRUE;
}


/*****************************************************************************/

/**
 * nm_setting_bond_get_num_options:
 * @setting: the #NMSettingBond
 *
 * Returns the number of options that are set in the legacy
 * #NMSettingBond:options property. This does not include other bond
 * properties which are not included in #NMSettingBond:options.
 *
 * Returns: the number of legacy bonding options
 *
 * Deprecated: use the option-specific getters instead.
 **/
guint32
nm_setting_bond_get_num_options (NMSettingBond *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);

	return _LAST_KERNEL_PROP - _FIRST_KERNEL_PROP + 1;
}

/**
 * nm_setting_bond_get_option:
 * @setting: the #NMSettingBond
 * @idx: index of the desired option, from 0 to
 * nm_setting_bond_get_num_options() - 1
 * @out_name: (out): on return, the name of the bonding option; this
 * value is owned by the setting and should not be modified
 * @out_value: (out): on return, the value of the name of the bonding
 * option; this value is owned by the setting and should not be modified
 *
 * Given an index, return the value of the bonding option at that index.  Indexes
 * are *not* guaranteed to be static across modifications to options done by
 * nm_setting_bond_add_option() and nm_setting_bond_remove_option(),
 * and should not be used to refer to options except for short periods of time
 * such as during option iteration.
 *
 * Returns: %TRUE on success if the index was valid and an option was found,
 * %FALSE if the index was invalid (ie, greater than the number of options
 * currently held by the setting)
 *
 * Deprecated: use the option-specific getters instead.
 **/
gboolean
nm_setting_bond_get_option (NMSettingBond *setting,
                            guint32 idx,
                            const char **out_name,
                            const char **out_value)
{
	NMSettingBondPrivate *priv;
	const char *kernel_name = NULL, *value = NULL;
	gboolean result = FALSE;

	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
	priv = NM_SETTING_BOND_GET_PRIVATE (setting);

	if (idx >= _LAST_KERNEL_PROP - _FIRST_KERNEL_PROP)
		goto out;
	idx += _FIRST_KERNEL_PROP;

	kernel_name = get_kernel_name (&props[idx]);
	g_assert (kernel_name);
	result = g_hash_table_lookup_extended (priv->options, kernel_name, NULL, (void **) &value);
	g_assert (result);

out:
	if (out_name)
		*out_name = kernel_name;
	if (out_value)
		*out_value = value;
	return result;
}

/**
 * nm_setting_bond_get_option_by_name:
 * @setting: the #NMSettingBond
 * @name: the option name for which to retrieve the value
 *
 * Returns the value associated with the bonding option specified by
 * @name, if it exists.
 *
 * Returns: the value, or %NULL if the key/value pair was never added to the
 * setting; the value is owned by the setting and must not be modified
 *
 * Deprecated: use the option-specific getters instead.
 **/
const char *
nm_setting_bond_get_option_by_name (NMSettingBond *setting,
                                    const char *name)
{
	return nm_setting_bond_get_string (setting, name);
}

/**
 * nm_setting_bond_add_option:
 * @setting: the #NMSettingBond
 * @name: name for the option
 * @value: value for the option
 *
 * Add an option to the table.  The option is compared to an internal list
 * of allowed options.  Option names may contain only alphanumeric characters
 * (ie [a-zA-Z0-9_]).  Adding a new name replaces any existing name/value pair
 * that may already exist.
 *
 * Returns: %TRUE if the option was valid and was added to the internal option
 * list, %FALSE if it was not.
 *
 * Deprecated: use the option-specific properties instead or nm_setting_bond_set_string()
 **/
gboolean
nm_setting_bond_add_option (NMSettingBond *setting,
                            const char *name,
                            const char *value)
{
	return nm_setting_bond_set_string (setting, name, value);
}

/**
 * nm_setting_bond_remove_option:
 * @setting: the #NMSettingBond
 * @name: name of the option to remove
 *
 * Remove the bonding option referenced by @name from the internal option
 * list. As the option list is deprected, you can no longer actually remove
 * an item from the option hash. Removing it is now equivalent to resetting
 * the default value.
 *
 * Returns: %TRUE if the option was found and removed from the internal option
 * list, %FALSE if it was not.
 *
 * Deprecated: use the option-specific properties instead.
 **/
gboolean
nm_setting_bond_remove_option (NMSettingBond *setting,
                               const char *name)
{
	/* We don't really remove the property, instead we reset the default value.
	 * Thus, the number of options is always constant (all of them) and the option
	 * hash always contains every kernel option. */
	nm_setting_bond_set_default (setting, name);
	return TRUE;
}

/**
 * nm_setting_bond_get_valid_options:
 * @setting: the #NMSettingBond
 *
 * Returns a list of valid bond options.
 *
 * Returns: (transfer none): a %NULL-terminated array of strings of valid bond options.
 *
 * Deprecated: the valid options are defined by the #NMSettingBond
 * properties.
 **/
const char **
nm_setting_bond_get_valid_options  (NMSettingBond *setting)
{
	return (const char **) nm_setting_bond_get_kernel_names ();
}

/**
 * nm_setting_bond_get_option_default:
 * @setting: the #NMSettingBond
 * @name: the name of the option
 *
 * Returns: the value of the bond option if not overridden by an entry in
 *   the #NMSettingBond:options property.
 *
 * Deprecated: Use the default values of the option-specific properties.
 **/
const char *
nm_setting_bond_get_option_default (NMSettingBond *setting, const char *name)
{
	BondProperty *prop;
	GValue defval = G_VALUE_INIT;

	g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);

	prop = find_property_by_name (name, NULL, TRUE);

	if (!prop)
		return NULL;

	if (G_UNLIKELY (prop->defval == NULL)) {
		g_value_init (&defval, prop->pspec->value_type);
		g_param_value_set_default (prop->pspec, &defval);
		prop->defval = g_strdup_value_contents (&defval);
		g_value_unset (&defval);
		g_return_val_if_fail (prop->defval, NULL);
	}
	return prop->defval;
}

/*****************************************************************/

static void
set_properties_from_hash (NMSettingBond *self, GHashTable *options)
{
	const char *value;
	guint i;

	g_object_freeze_notify (G_OBJECT (self));

	/* Set each property to the value given by @options, or if not present
	 * in @options, to the default value.
	 */
	for (i = _FIRST_KERNEL_PROP; i <= _LAST_KERNEL_PROP; i++) {
		const char *property_name = get_property_name (&props[i]);
		const char *kernel_name = get_kernel_name (&props[i]);
		GValue defval = G_VALUE_INIT;

		if (!g_hash_table_lookup_extended (options, kernel_name, NULL, (void **)&value)) {
			/* for setting options, we also support the new property names instead
			 * of the kernel names
			 **/
			if (!g_hash_table_lookup_extended (options, property_name, NULL, (void **)&value))
				value = NULL;
		}

		if (value)
			nm_setting_bond_set_string (self, kernel_name, value);
		else {
			g_value_init (&defval, props[i].pspec->value_type);
			g_param_value_set_default (props[i].pspec, &defval);
			g_object_set_property (G_OBJECT (self), property_name, &defval);
			g_value_unset (&defval);
		}
	}

	g_object_thaw_notify (G_OBJECT (self));
}

static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
	NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (setting);

	if (!priv->interface_name || !strlen (priv->interface_name)) {
		g_set_error_literal (error,
		                     NM_SETTING_BOND_ERROR,
		                     NM_SETTING_BOND_ERROR_MISSING_PROPERTY,
		                     _("property is missing"));
		g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_INTERFACE_NAME);
		return FALSE;
	}
	if (!nm_utils_iface_valid_name (priv->interface_name)) {
		g_set_error_literal (error,
		                     NM_SETTING_BOND_ERROR,
		                     NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
		                     _("property is invalid"));
		g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_INTERFACE_NAME);
		return FALSE;
	}

	/* Can only set one of miimon and arp_interval */
	if (priv->miimon > 0 && priv->arp_interval > 0) {
		g_set_error (error,
		             NM_SETTING_BOND_ERROR,
		             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
		             _("only one of '%s' and '%s' can be set"),
		             NM_SETTING_BOND_MIIMON,
		             NM_SETTING_BOND_ARP_INTERVAL);
		g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME,
		                priv->arp_ip_target == NULL && priv->arp_ip_target[0] ? NM_SETTING_BOND_ARP_INTERVAL : NM_SETTING_BOND_MIIMON);
	}

	if (!priv->mode) {
		g_set_error (error,
		             NM_SETTING_BOND_ERROR,
		             NM_SETTING_BOND_ERROR_MISSING_PROPERTY,
		             _("mandatory property '%s' is missing"),
		             NM_SETTING_BOND_MODE);
		g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_MODE);
		return FALSE;
	}
	if (!validate_property (&props[PROP_MODE], priv->mode)) {
		g_set_error (error,
		             NM_SETTING_BOND_ERROR,
		             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
		             _("'%s' is not a valid value for '%s'"),
		             priv->mode, NM_SETTING_BOND_MODE);
		g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_MODE);
		return FALSE;
	}

	/* Make sure mode is compatible with other settings */
	if (__NM_SETTING_BOND_MODE_IS_balance_alb (priv->mode) ||
	    __NM_SETTING_BOND_MODE_IS_balance_tlb (priv->mode)) {
		if (priv->arp_interval > 0) {
			g_set_error (error,
			             NM_SETTING_BOND_ERROR,
			             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
			             _("'%s=%s' is incompatible with '%s > 0'"),
			             NM_SETTING_BOND_MODE, priv->mode,
			             NM_SETTING_BOND_ARP_INTERVAL);
			g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_ARP_INTERVAL);
			return FALSE;
		}
	}

	if (__NM_SETTING_BOND_MODE_IS_active_backup (priv->mode)) {
		if (priv->primary && !nm_utils_iface_valid_name (priv->primary)) {
			g_set_error (error,
			             NM_SETTING_BOND_ERROR,
			             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
			             _("'%s' is not a valid interface name"),
			             priv->primary);
			g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_PRIMARY);
			return FALSE;
		}
	} else {
		if (priv->primary) {
			g_set_error (error,
			             NM_SETTING_BOND_ERROR,
			             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
			             _("'%s' is only valid for '%s=%s'"),
			             NM_SETTING_BOND_PRIMARY,
			             NM_SETTING_BOND_MODE, "active-backup");
			g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_PRIMARY);
			return FALSE;
		}
	}

	if (nm_setting_find_in_list (all_settings, NM_SETTING_INFINIBAND_SETTING_NAME)) {
		if (__NM_SETTING_BOND_MODE_IS_active_backup (priv->mode)) {
			g_set_error (error,
			             NM_SETTING_BOND_ERROR,
			             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
			             _("'%s=%s' is not a valid configuration for '%s'"),
			             NM_SETTING_BOND_MODE, priv->mode,
			             NM_SETTING_INFINIBAND_SETTING_NAME);
			g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_MODE);
			return FALSE;
		}
	}

	if (priv->miimon == 0) {
		/* updelay and downdelay can only be used with miimon */
		if (priv->updelay > 0) {
			g_set_error (error,
			             NM_SETTING_BOND_ERROR,
			             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
			             _("'%s' property requires '%s' property to be set"),
			             NM_SETTING_BOND_UPDELAY, NM_SETTING_BOND_MIIMON);
			g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_UPDELAY);
			return FALSE;
		}
		if (priv->downdelay > 0) {
			g_set_error (error,
			             NM_SETTING_BOND_ERROR,
			             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
			             _("'%s' property requires '%s' property to be set"),
			             NM_SETTING_BOND_DOWNDELAY, NM_SETTING_BOND_MIIMON);
			g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_DOWNDELAY);
			return FALSE;
		}
	}

	/* arp_ip_target can only be used with arp_interval, and must
	 * contain IPv4 addresses.
	 */
	if (priv->arp_interval > 0) {
		guint32 addr;
		int i;

		if (!priv->arp_ip_target) {
			g_set_error (error,
			             NM_SETTING_BOND_ERROR,
			             NM_SETTING_BOND_ERROR_MISSING_PROPERTY,
			             _("'%s' property requires '%s' property to be set"),
			             NM_SETTING_BOND_ARP_INTERVAL, NM_SETTING_BOND_ARP_IP_TARGET);
			g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_ARP_IP_TARGET);
			return FALSE;
		}

		if (!priv->arp_ip_target[0]) {
			g_set_error (error,
			             NM_SETTING_BOND_ERROR,
			             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
			             _("'%s' property is empty"),
			             NM_SETTING_BOND_ARP_IP_TARGET);
			g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_ARP_IP_TARGET);
			return FALSE;
		}

		for (i = 0; priv->arp_ip_target[i]; i++) {
			if (!inet_pton (AF_INET, priv->arp_ip_target[i], &addr)) {
				g_set_error (error,
				             NM_SETTING_BOND_ERROR,
				             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
				             _("'%s' is not a valid IPv4 address for '%s' property"),
				             priv->arp_ip_target[i], NM_SETTING_BOND_ARP_IP_TARGET);
				g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_ARP_IP_TARGET);
				return FALSE;
			}
		}
	} else {
		if (priv->arp_ip_target && priv->arp_ip_target[0]) {
			g_set_error (error,
			             NM_SETTING_BOND_ERROR,
			             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
			             _("'%s' property requires '%s' property to be set"),
			             NM_SETTING_BOND_ARP_IP_TARGET, NM_SETTING_BOND_ARP_INTERVAL);
			g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_ARP_IP_TARGET);
			return FALSE;
		}
	}

	/* FIXME: maybe we should not be too excessively about validating the strings,
	 * because the kernel might add new values (which we would then not support).
	 * OTOH, the checking above already requires some deep knowledge about the exact
	 * meaning of the flags, so, why check there, but not here?
	 **/
	if (priv->arp_validate && !validate_property (&props[PROP_ARP_VALIDATE], priv->arp_validate)) {
		g_set_error (error,
		             NM_SETTING_BOND_ERROR,
		             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
		             _("'%s' is not a valid value for '%s'"),
		             priv->arp_validate, NM_SETTING_BOND_ARP_VALIDATE);
		g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_ARP_VALIDATE);
		return FALSE;
	}

	if (priv->primary_reselect && !validate_property (&props[PROP_PRIMARY_RESELECT], priv->primary_reselect)) {
		g_set_error (error,
		             NM_SETTING_BOND_ERROR,
		             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
		             _("'%s' is not a valid value for '%s'"),
		             priv->primary_reselect, NM_SETTING_BOND_PRIMARY_RESELECT);
		g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_PRIMARY_RESELECT);
		return FALSE;
	}

	if (priv->fail_over_mac && !validate_property (&props[PROP_FAIL_OVER_MAC], priv->fail_over_mac)) {
		g_set_error (error,
		             NM_SETTING_BOND_ERROR,
		             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
		             _("'%s' is not a valid value for '%s'"),
		             priv->fail_over_mac, NM_SETTING_BOND_FAIL_OVER_MAC);
		g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_FAIL_OVER_MAC);
		return FALSE;
	}

	if (priv->ad_select && !validate_property (&props[PROP_AD_SELECT], priv->ad_select)) {
		g_set_error (error,
		             NM_SETTING_BOND_ERROR,
		             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
		             _("'%s' is not a valid value for '%s'"),
		             priv->ad_select, NM_SETTING_BOND_AD_SELECT);
		g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_AD_SELECT);
		return FALSE;
	}

	if (priv->xmit_hash_policy && !validate_property (&props[PROP_XMIT_HASH_POLICY], priv->xmit_hash_policy)) {
		g_set_error (error,
		             NM_SETTING_BOND_ERROR,
		             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
		             _("'%s' is not a valid value for '%s'"),
		             priv->xmit_hash_policy, NM_SETTING_BOND_XMIT_HASH_POLICY);
		g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_XMIT_HASH_POLICY);
		return FALSE;
	}

	return TRUE;
}

static const char *
get_virtual_iface_name (NMSetting *setting)
{
	NMSettingBond *self = NM_SETTING_BOND (setting);

	return nm_setting_bond_get_interface_name (self);
}

static gboolean
compare_property (NMSetting *setting,
                  NMSetting *other,
                  const GParamSpec *prop_spec,
                  NMSettingCompareFlags flags)
{
	BondProperty *prop = find_property_by_pspec (prop_spec, NULL, TRUE);
	gboolean result = FALSE;

	if (!prop)
		goto CHAIN;

	switch (prop->opt_type) {
	case TYPE_BOTH: {
		char *a0, *b0;
		const char *a, *b;

		g_object_get (setting, prop_spec->name, &a0, NULL);
		g_object_get (setting, prop_spec->name, &b0, NULL);

		a = a0;
		b = b0;
		if (!a || !b)
			result = (a == b);
		else if (strcmp (a, b) == 0)
			result = TRUE;
		else {
			int idx;

			if (validate_int (prop, a, &idx)) {
				if (!IS_VALID_LIST_INDEX (prop, idx))
					goto BOTH_FINISHED;
				a = prop->list[idx];
			}
			if (validate_int (prop, b, &idx)) {
				if (!IS_VALID_LIST_INDEX (prop, idx))
					goto BOTH_FINISHED;
				b = prop->list[idx];
			}
			result = (strcmp (a, b) == 0);
		}

BOTH_FINISHED:
		g_free (a0);
		g_free (b0);
		return result;
	}
	case TYPE_IP: {
		char **a, **b;
		struct in_addr *addr_a = NULL, *addr_b = NULL;

		g_object_get (setting, prop_spec->name, &a, NULL);
		g_object_get (setting, prop_spec->name, &b, NULL);

		if (!a || !a[0] || !b || !b[0])
			result = ((a ? a[0] : NULL) == (b ? b[0] : NULL));
		else {
			/* both arrays are not empty. We compare them by
			 * converting every item into a struct in_addr and looking
			 * whether we find it in the other array (and vice versa).
			 * If one of the addresses cannot be converted, the result
			 * is always false (because nothing compares to an invalid property).
			 **/

			guint i, j;
			guint alen = g_strv_length (a);
			guint blen = g_strv_length (b);

			/* convert all strings to struct in_addr */
			addr_a = g_new (struct in_addr, alen);
			for (i = 0; i < alen; i++) {
				if (!inet_aton (a[i], &addr_a[i]))
					goto IP_FINISHED;
			}

			addr_b = g_new (struct in_addr, blen);
			for (i = 0; i < blen; i++) {
				if (!inet_aton (b[i], &addr_b[i]))
					goto IP_FINISHED;
			}

			/* ensure that we find every address in the other array too */
			for (i = 0; i < alen; i++) {
				for (j = 0; j < blen; j++) {
					if (addr_a[i].s_addr == addr_b[j].s_addr)
						break;
				}
				if (j >= blen)
					goto IP_FINISHED;
			}

			for (i = 0; i < blen; i++) {
				for (j = 0; j < alen; j++) {
					if (addr_b[i].s_addr == addr_a[j].s_addr)
						break;
				}
				if (j >= alen)
					goto IP_FINISHED;
			}
			result = TRUE;
		}
IP_FINISHED:
		g_free (addr_a);
		g_free (addr_b);
		g_strfreev (a);
		g_strfreev (b);
		return result;
	}
	default:
		/* other types shall be compared by the default implementation. */
		goto CHAIN;
	}

CHAIN:
	return NM_SETTING_CLASS (nm_setting_bond_parent_class)->compare_property (setting, other, prop_spec, flags);
}


static void
nm_setting_bond_init (NMSettingBond *setting)
{
	NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (setting);

	priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);

	g_object_set (setting, NM_SETTING_NAME, NM_SETTING_BOND_SETTING_NAME, NULL);
}

static void
constructed (GObject *object)
{
	G_OBJECT_CLASS (nm_setting_bond_parent_class)->constructed (object);

	g_assert (g_hash_table_size (NM_SETTING_BOND_GET_PRIVATE (object)->options) == (_LAST_KERNEL_PROP - _FIRST_KERNEL_PROP + 1));
}

static void
finalize (GObject *object)
{
	NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);

	g_assert (g_hash_table_size (priv->options) == (_LAST_KERNEL_PROP - _FIRST_KERNEL_PROP + 1));

	g_free (priv->interface_name);
	g_free (priv->mode);
	g_free (priv->primary);
	g_strfreev (priv->arp_ip_target);
	g_hash_table_destroy (priv->options);

	G_OBJECT_CLASS (nm_setting_bond_parent_class)->finalize (object);
}

static void
set_property (GObject *object, guint prop_id,
              const GValue *value, GParamSpec *pspec)
{
	NMSettingBond *setting = NM_SETTING_BOND (object);
	NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);
	BondProperty *prop = find_property_by_pspec (pspec, NULL, TRUE);
	char *kernel_value = NULL;

	switch (prop_id) {
	case PROP_INTERFACE_NAME:
		g_free (priv->interface_name);
		priv->interface_name = g_value_dup_string (value);
		break;
	case PROP_MODE:
		g_free (priv->mode);
		priv->mode = g_value_dup_string (value);
		kernel_value = g_value_dup_string (value);
		break;
	case PROP_MIIMON:
		priv->miimon = g_value_get_int (value);
		kernel_value = g_strdup_printf ("%u", g_value_get_int (value));
		break;
	case PROP_DOWNDELAY:
		priv->downdelay = g_value_get_int (value);
		kernel_value = g_strdup_printf ("%u", g_value_get_int (value));
		break;
	case PROP_UPDELAY:
		priv->updelay = g_value_get_int (value);
		kernel_value = g_strdup_printf ("%u", g_value_get_int (value));
		break;
	case PROP_ARP_INTERVAL:
		priv->arp_interval = g_value_get_int (value);
		kernel_value = g_strdup_printf ("%u", g_value_get_int (value));
		break;
	case PROP_ARP_IP_TARGET:
		g_strfreev (priv->arp_ip_target);
		priv->arp_ip_target = g_value_dup_boxed (value);
		kernel_value = priv->arp_ip_target ? g_strjoinv (",", priv->arp_ip_target) : g_strdup ("");
		break;
	case PROP_ARP_VALIDATE:
		g_free (priv->arp_validate);
		priv->arp_validate = g_value_dup_string (value);
		kernel_value = g_value_dup_string (value);
		break;
	case PROP_PRIMARY:
		g_free (priv->primary);
		priv->primary = g_value_dup_string (value);
		kernel_value = g_value_dup_string (value);
		break;
	case PROP_PRIMARY_RESELECT:
		g_free (priv->primary_reselect);
		priv->primary_reselect = g_value_dup_string (value);
		kernel_value = g_value_dup_string (value);
		break;
	case PROP_FAIL_OVER_MAC:
		g_free (priv->fail_over_mac);
		priv->fail_over_mac = g_value_dup_string (value);
		kernel_value = g_value_dup_string (value);
		break;
	case PROP_USE_CARRIER:
		priv->use_carrier = !!g_value_get_int (value);
		kernel_value = g_strdup_printf ("%u", priv->use_carrier);
		break;
	case PROP_AD_SELECT:
		g_free (priv->ad_select);
		priv->ad_select = g_value_dup_string (value);
		kernel_value = g_value_dup_string (value);
		break;
	case PROP_XMIT_HASH_POLICY:
		g_free (priv->xmit_hash_policy);
		priv->xmit_hash_policy = g_value_dup_string (value);
		kernel_value = g_value_dup_string (value);
		break;
	case PROP_RESEND_IGMP:
		priv->resend_igmp = g_value_get_int (value);
		kernel_value = g_strdup_printf ("%u", g_value_get_int (value));
		break;
	case PROP_OPTIONS:
		set_properties_from_hash (setting, g_value_get_boxed (value));
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}

	if (prop) {
		const char *kernel_name = get_kernel_name (prop);
		const char *old_value;

		if (   !g_hash_table_lookup_extended (priv->options, kernel_name, NULL, (void **) &old_value)
		    || g_strcmp0 (old_value, kernel_value)) {
			g_hash_table_insert (priv->options, (void *) kernel_name, kernel_value);
			g_object_notify (object, NM_SETTING_BOND_OPTIONS);
		}
	}
}

static void
get_property (GObject *object, guint prop_id,
              GValue *value, GParamSpec *pspec)
{
	NMSettingBond *setting = NM_SETTING_BOND (object);
	NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);

	switch (prop_id) {
	case PROP_INTERFACE_NAME:
		g_value_set_string (value, nm_setting_bond_get_interface_name (setting));
		break;
	case PROP_MODE:
		g_value_set_string (value, nm_setting_bond_get_mode (setting));
		break;
	case PROP_MIIMON:
		g_value_set_int (value, nm_setting_bond_get_miimon (setting));
		break;
	case PROP_DOWNDELAY:
		g_value_set_int (value, nm_setting_bond_get_downdelay (setting));
		break;
	case PROP_UPDELAY:
		g_value_set_int (value, nm_setting_bond_get_updelay (setting));
		break;
	case PROP_ARP_INTERVAL:
		g_value_set_int (value, nm_setting_bond_get_arp_interval (setting));
		break;
	case PROP_ARP_IP_TARGET:
		g_value_set_boxed (value, nm_setting_bond_get_arp_ip_target (setting));
		break;
	case PROP_ARP_VALIDATE:
		g_value_set_string (value, nm_setting_bond_get_arp_validate (setting));
		break;
	case PROP_PRIMARY:
		g_value_set_string (value, nm_setting_bond_get_primary (setting));
		break;
	case PROP_PRIMARY_RESELECT:
		g_value_set_string (value, nm_setting_bond_get_primary_reselect (setting));
		break;
	case PROP_FAIL_OVER_MAC:
		g_value_set_string (value, nm_setting_bond_get_fail_over_mac (setting));
		break;
	case PROP_USE_CARRIER:
		g_value_set_int (value, nm_setting_bond_get_use_carrier (setting));
		break;
	case PROP_AD_SELECT:
		g_value_set_string (value, nm_setting_bond_get_ad_select (setting));
		break;
	case PROP_XMIT_HASH_POLICY:
		g_value_set_string (value, nm_setting_bond_get_xmit_hash_policy (setting));
		break;
	case PROP_RESEND_IGMP:
		g_value_set_int (value, nm_setting_bond_get_resend_igmp (setting));
		break;
	case PROP_OPTIONS:
		g_value_set_boxed (value, priv->options);
        break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

static void
nm_setting_bond_class_init (NMSettingBondClass *setting_class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
	NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
	guint i;

	g_type_class_add_private (setting_class, sizeof (NMSettingBondPrivate));

	/* virtual methods */
	object_class->set_property           = set_property;
	object_class->get_property           = get_property;
	object_class->constructed            = constructed;
	object_class->finalize               = finalize;
	parent_class->verify                 = verify;
	parent_class->compare_property       = compare_property;
	parent_class->get_virtual_iface_name = get_virtual_iface_name;

	/* Properties */
	/**
	 * NMSettingBond:interface-name:
	 *
	 * The name of the virtual in-kernel bonding network interface
	 **/
	props[PROP_INTERFACE_NAME].pspec =
	    g_param_spec_string (NM_SETTING_BOND_INTERFACE_NAME,
	                         "InterfaceName",
	                         "The name of the virtual in-kernel bonding network interface",
	                         NULL,
	                         G_PARAM_READWRITE);

	/**
	 * NMSettingBond:mode:
	 *
	 * The bonding mode. One of 'balance-rr', 'active-backup',
	 * 'balance-xor', 'broadcast', '802.3ad', 'balance-tlb', or
	 * 'balance-alb'.
	 **/
	props[PROP_MODE].pspec =
	    g_param_spec_string (NM_SETTING_BOND_MODE,
	                         "Mode",
	                         "The bonding mode",
	                         "balance-rr",
	                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT);

	/**
	 * NMSettingBond:miimon:
	 *
	 * The MII link monitoring frequency, in milliseconds. Either this
	 * or #NMSettingBond:arp-interval should be set, and they can't
	 * both be set.
	 *
	 * Since: 0.9.10
	 **/
	props[PROP_MIIMON].pspec =
	    g_param_spec_int (NM_SETTING_BOND_MIIMON,
	                       "miimon",
	                       "The MII link monitoring frequence",
	                       0, G_MAXINT, 100,
	                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT);

	/**
	 * NMSettingBond:downdelay:
	 *
	 * The time, in milliseconds, to wait before disabling a slave
	 * after it goes down. Only valid if #NMSettingBond:miimon is
	 * non-0.
	 *
	 * Since: 0.9.10
	 **/
	props[PROP_DOWNDELAY].pspec =
	    g_param_spec_int (NM_SETTING_BOND_DOWNDELAY,
	                       "downdelay",
	                       "downdelay",
	                       0, G_MAXINT, 0,
	                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT);

	/**
	 * NMSettingBond:updelay:
	 *
	 * The time, in milliseconds, to wait before enabling a slave
	 * after it comes up. Only valid if #NMSettingBond:miimon is
	 * non-0.
	 *
	 * Since: 0.9.10
	 **/
	props[PROP_UPDELAY].pspec =
	    g_param_spec_int (NM_SETTING_BOND_UPDELAY,
	                       "updelay",
	                       "updelay",
	                       0, G_MAXINT, 0,
	                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT);

	/**
	 * NMSettingBond:arp-interval:
	 *
	 * The ARP-based link monitoring frequency, in milliseconds.
	 * Either this or #NMSettingBond:miimon should be set, and they
	 * can't both be set.
	 *
	 * Since: 0.9.10
	 **/
	props[PROP_ARP_INTERVAL].pspec =
	    g_param_spec_int (NM_SETTING_BOND_ARP_INTERVAL,
	                      "ARP interval",
	                      "The ARP-based link monitoring frequence",
	                       0, G_MAXINT, 0,
	                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT);

	/**
	 * NMSettingBond:arp-ip-target:
	 *
	 * An array of IPv4 addresses to ping when using ARP-based link monitoring.
	 * This only has an effect when #NMSettingBond:arp-interval is also set.
	 *
	 * Since: 0.9.10
	 **/
	props[PROP_ARP_IP_TARGET].pspec =
	    g_param_spec_boxed (NM_SETTING_BOND_ARP_IP_TARGET,
	                        "ARP IP target",
	                        "ARP monitoring target IP addresses",
	                        G_TYPE_STRV,
	                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT);

	/**
	 * NMSettingBond:arp-validate:
	 *
	 * Specifies whether or not ARP probes and replies should be
	 * validated in the active-backup mode. One of
	 * 'none', 'active', 'backup', 'all'.
	 *
	 * Since: 0.9.10
	 **/
	props[PROP_ARP_VALIDATE].pspec =
	    g_param_spec_string (NM_SETTING_BOND_ARP_VALIDATE,
	                         "arp-validate",
	                         "Specifies whether or not ARP probes and replies should "
	                         "be validate in the active-backup mode",
	                         "none",
	                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT);

	/**
	 * NMSettingBond:primary:
	 *
	 * The primary interface to use in 'active-backup' mode.
	 **/
	props[PROP_PRIMARY].pspec =
	    g_param_spec_string (NM_SETTING_BOND_PRIMARY,
	                         "Primary",
	                         "The primary interface",
	                         NULL,
	                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT);

	/**
	 * NMSettingBond:primary-reselect:
	 *
	 * Specifies the reselection policy for the primary slave.
	 * One of 'always', 'better', 'failure'.
	 *
	 * Since: 0.9.10
	 **/
	props[PROP_PRIMARY_RESELECT].pspec =
	    g_param_spec_string (NM_SETTING_BOND_PRIMARY_RESELECT,
	                         "primary-reselect",
	                         "Specifies the reselection policy for the primary slave",
	                         "always",
	                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT);

	/**
	 * NMSettingBond:fail-over-mac:
	 *
	 * Specifies whether active-backup mode should set all slaves to
	 * the same MAC address at enslavement (the traditional
	 * behavior), or, when enabled, perform special handling of the
	 * bond's MAC address in accordance with the selected policy.
	 * One of 'none', 'active', 'follow'.
	 *
	 * Since: 0.9.10
	 **/
	props[PROP_FAIL_OVER_MAC].pspec =
	    g_param_spec_string (NM_SETTING_BOND_FAIL_OVER_MAC,
	                         "fail-over-mac",
	                         "fail_over_mac",
	                         "none",
	                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT);

	/**
	 * NMSettingBond:use-carrier:
	 *
	 * Specifies whether or not miimon should use MII or ETHTOOL
	 * ioctls vs. netif_carrier_ok() to determine the link
	 * status.
	 *
	 * Since: 0.9.10
	 **/
	props[PROP_USE_CARRIER].pspec =
	    g_param_spec_int (NM_SETTING_BOND_USE_CARRIER,
	                       "use-carrier",
	                       "use_carrier",
	                       0, 1, 1,
	                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT);

	/**
	 * NMSettingBond:ad-select:
	 *
	 * Specifies the 802.3ad aggregation selection logic to use.
	 * One of 'stable', 'bandwidth', or 'count'.
	 **/
	props[PROP_AD_SELECT].pspec =
	    g_param_spec_string (NM_SETTING_BOND_AD_SELECT,
	                         "ad-select",
	                         "ad_select",
	                         "stable",
	                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT);

	/**
	 * NMSettingBond:xmit-hash-policy:
	 *
	 * Selects the transmit hash policy to use for slave selection in
	 * balance-xor and 802.3ad modes. One of 'layer2', 'layer2+3',
	 * 'layer3+4', 'encap2+3', or 'encap3+4'.
	 *
	 **/
	props[PROP_XMIT_HASH_POLICY].pspec =
	    g_param_spec_string (NM_SETTING_BOND_XMIT_HASH_POLICY,
	                         "xmit-hash-policy",
	                         "xmit_hash_policy",
	                         "layer2",
	                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT);

	/**
	 * NMSettingBond:resend-igmp:
	 *
	 * Specifies the number of IGMP membership reports to be issued after
	 * a failover event. One membership report is issued immediately after
	 * the failover, subsequent packets are sent in each 200ms interval.
	 *
	 * The valid range is 0 - 255; the default value is 1. A value of 0
	 * prevents the IGMP membership report from being issued in response
	 * to the failover event.
	 *
	 * Since: 0.9.10
	 **/
	props[PROP_RESEND_IGMP].pspec =
	    g_param_spec_int (NM_SETTING_BOND_RESEND_IGMP,
	                       "resend-igmp",
	                       "resend_igmp",
	                       0, 255, 1,
	                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT);

	/**
	 * NMSettingBond:options:
	 *
	 * Dictionary of key/value pairs of bonding options.  Both keys
	 * and values must be strings. Option names must contain only
	 * alphanumeric characters (ie, [a-zA-Z0-9_).
	 *
	 * Deprecated: use the specific properties
	 **/
	props[PROP_OPTIONS].pspec =
	    _nm_param_spec_specialized (NM_SETTING_BOND_OPTIONS,
	                                "Options",
	                                "Dictionary of key/value pairs of bonding "
	                                "options.  Both keys and values must be "
	                                "strings.  Option names must contain only "
	                                "alphanumeric characters (ie, [a-zA-Z0-9_]).",
	                                DBUS_TYPE_G_MAP_OF_STRING,
	                                G_PARAM_READWRITE);

	/* Skip PROP_0 */
	for (i = 1; i < LAST_PROP; i++)
		g_object_class_install_property (object_class, i, props[i].pspec);
}