12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 21ef8019bSDavid S. Miller /* 31ef8019bSDavid S. Miller * drivers/net/bond/bond_options.h - bonding options 41ef8019bSDavid S. Miller * Copyright (c) 2013 Nikolay Aleksandrov <nikolay@redhat.com> 51ef8019bSDavid S. Miller */ 61ef8019bSDavid S. Miller 71ef8019bSDavid S. Miller #ifndef _NET_BOND_OPTIONS_H 81ef8019bSDavid S. Miller #define _NET_BOND_OPTIONS_H 91ef8019bSDavid S. Miller 10*949d6b40SJakub Kicinski #include <linux/bits.h> 11*949d6b40SJakub Kicinski #include <linux/limits.h> 12*949d6b40SJakub Kicinski #include <linux/types.h> 13*949d6b40SJakub Kicinski #include <linux/string.h> 14*949d6b40SJakub Kicinski 15*949d6b40SJakub Kicinski struct netlink_ext_ack; 16*949d6b40SJakub Kicinski struct nlattr; 17*949d6b40SJakub Kicinski 181ef8019bSDavid S. Miller #define BOND_OPT_MAX_NAMELEN 32 191ef8019bSDavid S. Miller #define BOND_OPT_VALID(opt) ((opt) < BOND_OPT_LAST) 201ef8019bSDavid S. Miller #define BOND_MODE_ALL_EX(x) (~(x)) 211ef8019bSDavid S. Miller 221ef8019bSDavid S. Miller /* Option flags: 231ef8019bSDavid S. Miller * BOND_OPTFLAG_NOSLAVES - check if the bond device is empty before setting 241ef8019bSDavid S. Miller * BOND_OPTFLAG_IFDOWN - check if the bond device is down before setting 251ef8019bSDavid S. Miller * BOND_OPTFLAG_RAWVAL - the option parses the value itself 261ef8019bSDavid S. Miller */ 271ef8019bSDavid S. Miller enum { 281ef8019bSDavid S. Miller BOND_OPTFLAG_NOSLAVES = BIT(0), 291ef8019bSDavid S. Miller BOND_OPTFLAG_IFDOWN = BIT(1), 301ef8019bSDavid S. Miller BOND_OPTFLAG_RAWVAL = BIT(2) 311ef8019bSDavid S. Miller }; 321ef8019bSDavid S. Miller 331ef8019bSDavid S. Miller /* Value type flags: 341ef8019bSDavid S. Miller * BOND_VALFLAG_DEFAULT - mark the value as default 351ef8019bSDavid S. Miller * BOND_VALFLAG_(MIN|MAX) - mark the value as min/max 361ef8019bSDavid S. Miller */ 371ef8019bSDavid S. Miller enum { 381ef8019bSDavid S. Miller BOND_VALFLAG_DEFAULT = BIT(0), 391ef8019bSDavid S. Miller BOND_VALFLAG_MIN = BIT(1), 401ef8019bSDavid S. Miller BOND_VALFLAG_MAX = BIT(2) 411ef8019bSDavid S. Miller }; 421ef8019bSDavid S. Miller 431ef8019bSDavid S. Miller /* Option IDs, their bit positions correspond to their IDs */ 441ef8019bSDavid S. Miller enum { 451ef8019bSDavid S. Miller BOND_OPT_MODE, 461ef8019bSDavid S. Miller BOND_OPT_PACKETS_PER_SLAVE, 471ef8019bSDavid S. Miller BOND_OPT_XMIT_HASH, 481ef8019bSDavid S. Miller BOND_OPT_ARP_VALIDATE, 491ef8019bSDavid S. Miller BOND_OPT_ARP_ALL_TARGETS, 501ef8019bSDavid S. Miller BOND_OPT_FAIL_OVER_MAC, 511ef8019bSDavid S. Miller BOND_OPT_ARP_INTERVAL, 521ef8019bSDavid S. Miller BOND_OPT_ARP_TARGETS, 531ef8019bSDavid S. Miller BOND_OPT_DOWNDELAY, 541ef8019bSDavid S. Miller BOND_OPT_UPDELAY, 551ef8019bSDavid S. Miller BOND_OPT_LACP_RATE, 561ef8019bSDavid S. Miller BOND_OPT_MINLINKS, 571ef8019bSDavid S. Miller BOND_OPT_AD_SELECT, 581ef8019bSDavid S. Miller BOND_OPT_NUM_PEER_NOTIF, 591ef8019bSDavid S. Miller BOND_OPT_MIIMON, 601ef8019bSDavid S. Miller BOND_OPT_PRIMARY, 611ef8019bSDavid S. Miller BOND_OPT_PRIMARY_RESELECT, 621ef8019bSDavid S. Miller BOND_OPT_USE_CARRIER, 631ef8019bSDavid S. Miller BOND_OPT_ACTIVE_SLAVE, 641ef8019bSDavid S. Miller BOND_OPT_QUEUE_ID, 651ef8019bSDavid S. Miller BOND_OPT_ALL_SLAVES_ACTIVE, 661ef8019bSDavid S. Miller BOND_OPT_RESEND_IGMP, 671ef8019bSDavid S. Miller BOND_OPT_LP_INTERVAL, 681ef8019bSDavid S. Miller BOND_OPT_SLAVES, 691ef8019bSDavid S. Miller BOND_OPT_TLB_DYNAMIC_LB, 706791e466SMahesh Bandewar BOND_OPT_AD_ACTOR_SYS_PRIO, 7174514957SMahesh Bandewar BOND_OPT_AD_ACTOR_SYSTEM, 72d22a5fc0SMahesh Bandewar BOND_OPT_AD_USER_PORT_KEY, 73205845a3SNikolay Aleksandrov BOND_OPT_NUM_PEER_NOTIF_ALIAS, 7407a4ddecSVincent Bernat BOND_OPT_PEER_NOTIF_DELAY, 753a755cd8SHangbin Liu BOND_OPT_LACP_ACTIVE, 765944b5abSHangbin Liu BOND_OPT_MISSED_MAX, 77129e3c1bSHangbin Liu BOND_OPT_NS_TARGETS, 780a2ff7ccSHangbin Liu BOND_OPT_PRIO, 791ef8019bSDavid S. Miller BOND_OPT_LAST 801ef8019bSDavid S. Miller }; 811ef8019bSDavid S. Miller 821ef8019bSDavid S. Miller /* This structure is used for storing option values and for passing option 831ef8019bSDavid S. Miller * values when changing an option. The logic when used as an arg is as follows: 84841e9564SHangbin Liu * - if value != ULLONG_MAX -> parse value 85841e9564SHangbin Liu * - if string != NULL -> parse string 86841e9564SHangbin Liu * - if the opt is RAW data and length less than maxlen, 87841e9564SHangbin Liu * copy the data to extra storage 881ef8019bSDavid S. Miller */ 89841e9564SHangbin Liu 90841e9564SHangbin Liu #define BOND_OPT_EXTRA_MAXLEN 16 911ef8019bSDavid S. Miller struct bond_opt_value { 921ef8019bSDavid S. Miller char *string; 931ef8019bSDavid S. Miller u64 value; 941ef8019bSDavid S. Miller u32 flags; 95f2b3b28cSHangbin Liu union { 96841e9564SHangbin Liu char extra[BOND_OPT_EXTRA_MAXLEN]; 97f2b3b28cSHangbin Liu struct net_device *slave_dev; 98f2b3b28cSHangbin Liu }; 991ef8019bSDavid S. Miller }; 1001ef8019bSDavid S. Miller 1011ef8019bSDavid S. Miller struct bonding; 1021ef8019bSDavid S. Miller 1031ef8019bSDavid S. Miller struct bond_option { 1041ef8019bSDavid S. Miller int id; 1051ef8019bSDavid S. Miller const char *name; 1061ef8019bSDavid S. Miller const char *desc; 1071ef8019bSDavid S. Miller u32 flags; 1081ef8019bSDavid S. Miller 1091ef8019bSDavid S. Miller /* unsuppmodes is used to denote modes in which the option isn't 1101ef8019bSDavid S. Miller * supported. 1111ef8019bSDavid S. Miller */ 1121ef8019bSDavid S. Miller unsigned long unsuppmodes; 1131ef8019bSDavid S. Miller /* supported values which this option can have, can be a subset of 1141ef8019bSDavid S. Miller * BOND_OPTVAL_RANGE's value range 1151ef8019bSDavid S. Miller */ 1161ef8019bSDavid S. Miller const struct bond_opt_value *values; 1171ef8019bSDavid S. Miller 1181ef8019bSDavid S. Miller int (*set)(struct bonding *bond, const struct bond_opt_value *val); 1191ef8019bSDavid S. Miller }; 1201ef8019bSDavid S. Miller 1211ef8019bSDavid S. Miller int __bond_opt_set(struct bonding *bond, unsigned int option, 1222bff369bSJonathan Toppins struct bond_opt_value *val, 1232bff369bSJonathan Toppins struct nlattr *bad_attr, struct netlink_ext_ack *extack); 1247a7e96e0SVlad Yasevich int __bond_opt_set_notify(struct bonding *bond, unsigned int option, 1257a7e96e0SVlad Yasevich struct bond_opt_value *val); 1261ef8019bSDavid S. Miller int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf); 1271ef8019bSDavid S. Miller 1281ef8019bSDavid S. Miller const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt, 1291ef8019bSDavid S. Miller struct bond_opt_value *val); 1301ef8019bSDavid S. Miller const struct bond_option *bond_opt_get(unsigned int option); 1311ef8019bSDavid S. Miller const struct bond_option *bond_opt_get_by_name(const char *name); 1321ef8019bSDavid S. Miller const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val); 1331ef8019bSDavid S. Miller 1341ef8019bSDavid S. Miller /* This helper is used to initialize a bond_opt_value structure for parameter 1351ef8019bSDavid S. Miller * passing. There should be either a valid string or value, but not both. 1361ef8019bSDavid S. Miller * When value is ULLONG_MAX then string will be used. 1371ef8019bSDavid S. Miller */ 1381ef8019bSDavid S. Miller static inline void __bond_opt_init(struct bond_opt_value *optval, 139841e9564SHangbin Liu char *string, u64 value, 140841e9564SHangbin Liu void *extra, size_t extra_len) 1411ef8019bSDavid S. Miller { 1421ef8019bSDavid S. Miller memset(optval, 0, sizeof(*optval)); 1431ef8019bSDavid S. Miller optval->value = ULLONG_MAX; 144841e9564SHangbin Liu if (value != ULLONG_MAX) 1451ef8019bSDavid S. Miller optval->value = value; 146841e9564SHangbin Liu else if (string) 147841e9564SHangbin Liu optval->string = string; 148f2b3b28cSHangbin Liu 149f2b3b28cSHangbin Liu if (extra && extra_len <= BOND_OPT_EXTRA_MAXLEN) 150841e9564SHangbin Liu memcpy(optval->extra, extra, extra_len); 1511ef8019bSDavid S. Miller } 152841e9564SHangbin Liu #define bond_opt_initval(optval, value) __bond_opt_init(optval, NULL, value, NULL, 0) 153841e9564SHangbin Liu #define bond_opt_initstr(optval, str) __bond_opt_init(optval, str, ULLONG_MAX, NULL, 0) 154841e9564SHangbin Liu #define bond_opt_initextra(optval, extra, extra_len) \ 155841e9564SHangbin Liu __bond_opt_init(optval, NULL, ULLONG_MAX, extra, extra_len) 156f2b3b28cSHangbin Liu #define bond_opt_slave_initval(optval, slave_dev, value) \ 157f2b3b28cSHangbin Liu __bond_opt_init(optval, NULL, value, slave_dev, sizeof(struct net_device *)) 1581ef8019bSDavid S. Miller 1591ef8019bSDavid S. Miller void bond_option_arp_ip_targets_clear(struct bonding *bond); 160129e3c1bSHangbin Liu #if IS_ENABLED(CONFIG_IPV6) 161129e3c1bSHangbin Liu void bond_option_ns_ip6_targets_clear(struct bonding *bond); 162129e3c1bSHangbin Liu #endif 1631ef8019bSDavid S. Miller 1641ef8019bSDavid S. Miller #endif /* _NET_BOND_OPTIONS_H */ 165