Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * drivers/net/bond/bond_options.h - bonding options
0004  * Copyright (c) 2013 Nikolay Aleksandrov <nikolay@redhat.com>
0005  */
0006 
0007 #ifndef _NET_BOND_OPTIONS_H
0008 #define _NET_BOND_OPTIONS_H
0009 
0010 #include <linux/bits.h>
0011 #include <linux/limits.h>
0012 #include <linux/types.h>
0013 #include <linux/string.h>
0014 
0015 struct netlink_ext_ack;
0016 struct nlattr;
0017 
0018 #define BOND_OPT_MAX_NAMELEN 32
0019 #define BOND_OPT_VALID(opt) ((opt) < BOND_OPT_LAST)
0020 #define BOND_MODE_ALL_EX(x) (~(x))
0021 
0022 /* Option flags:
0023  * BOND_OPTFLAG_NOSLAVES - check if the bond device is empty before setting
0024  * BOND_OPTFLAG_IFDOWN - check if the bond device is down before setting
0025  * BOND_OPTFLAG_RAWVAL - the option parses the value itself
0026  */
0027 enum {
0028     BOND_OPTFLAG_NOSLAVES   = BIT(0),
0029     BOND_OPTFLAG_IFDOWN = BIT(1),
0030     BOND_OPTFLAG_RAWVAL = BIT(2)
0031 };
0032 
0033 /* Value type flags:
0034  * BOND_VALFLAG_DEFAULT - mark the value as default
0035  * BOND_VALFLAG_(MIN|MAX) - mark the value as min/max
0036  */
0037 enum {
0038     BOND_VALFLAG_DEFAULT    = BIT(0),
0039     BOND_VALFLAG_MIN    = BIT(1),
0040     BOND_VALFLAG_MAX    = BIT(2)
0041 };
0042 
0043 /* Option IDs, their bit positions correspond to their IDs */
0044 enum {
0045     BOND_OPT_MODE,
0046     BOND_OPT_PACKETS_PER_SLAVE,
0047     BOND_OPT_XMIT_HASH,
0048     BOND_OPT_ARP_VALIDATE,
0049     BOND_OPT_ARP_ALL_TARGETS,
0050     BOND_OPT_FAIL_OVER_MAC,
0051     BOND_OPT_ARP_INTERVAL,
0052     BOND_OPT_ARP_TARGETS,
0053     BOND_OPT_DOWNDELAY,
0054     BOND_OPT_UPDELAY,
0055     BOND_OPT_LACP_RATE,
0056     BOND_OPT_MINLINKS,
0057     BOND_OPT_AD_SELECT,
0058     BOND_OPT_NUM_PEER_NOTIF,
0059     BOND_OPT_MIIMON,
0060     BOND_OPT_PRIMARY,
0061     BOND_OPT_PRIMARY_RESELECT,
0062     BOND_OPT_USE_CARRIER,
0063     BOND_OPT_ACTIVE_SLAVE,
0064     BOND_OPT_QUEUE_ID,
0065     BOND_OPT_ALL_SLAVES_ACTIVE,
0066     BOND_OPT_RESEND_IGMP,
0067     BOND_OPT_LP_INTERVAL,
0068     BOND_OPT_SLAVES,
0069     BOND_OPT_TLB_DYNAMIC_LB,
0070     BOND_OPT_AD_ACTOR_SYS_PRIO,
0071     BOND_OPT_AD_ACTOR_SYSTEM,
0072     BOND_OPT_AD_USER_PORT_KEY,
0073     BOND_OPT_NUM_PEER_NOTIF_ALIAS,
0074     BOND_OPT_PEER_NOTIF_DELAY,
0075     BOND_OPT_LACP_ACTIVE,
0076     BOND_OPT_MISSED_MAX,
0077     BOND_OPT_NS_TARGETS,
0078     BOND_OPT_PRIO,
0079     BOND_OPT_LAST
0080 };
0081 
0082 /* This structure is used for storing option values and for passing option
0083  * values when changing an option. The logic when used as an arg is as follows:
0084  * - if value != ULLONG_MAX -> parse value
0085  * - if string != NULL -> parse string
0086  * - if the opt is RAW data and length less than maxlen,
0087  *   copy the data to extra storage
0088  */
0089 
0090 #define BOND_OPT_EXTRA_MAXLEN 16
0091 struct bond_opt_value {
0092     char *string;
0093     u64 value;
0094     u32 flags;
0095     union {
0096         char extra[BOND_OPT_EXTRA_MAXLEN];
0097         struct net_device *slave_dev;
0098     };
0099 };
0100 
0101 struct bonding;
0102 
0103 struct bond_option {
0104     int id;
0105     const char *name;
0106     const char *desc;
0107     u32 flags;
0108 
0109     /* unsuppmodes is used to denote modes in which the option isn't
0110      * supported.
0111      */
0112     unsigned long unsuppmodes;
0113     /* supported values which this option can have, can be a subset of
0114      * BOND_OPTVAL_RANGE's value range
0115      */
0116     const struct bond_opt_value *values;
0117 
0118     int (*set)(struct bonding *bond, const struct bond_opt_value *val);
0119 };
0120 
0121 int __bond_opt_set(struct bonding *bond, unsigned int option,
0122            struct bond_opt_value *val,
0123            struct nlattr *bad_attr, struct netlink_ext_ack *extack);
0124 int __bond_opt_set_notify(struct bonding *bond, unsigned int option,
0125               struct bond_opt_value *val);
0126 int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf);
0127 
0128 const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt,
0129                         struct bond_opt_value *val);
0130 const struct bond_option *bond_opt_get(unsigned int option);
0131 const struct bond_option *bond_opt_get_by_name(const char *name);
0132 const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val);
0133 
0134 /* This helper is used to initialize a bond_opt_value structure for parameter
0135  * passing. There should be either a valid string or value, but not both.
0136  * When value is ULLONG_MAX then string will be used.
0137  */
0138 static inline void __bond_opt_init(struct bond_opt_value *optval,
0139                    char *string, u64 value,
0140                    void *extra, size_t extra_len)
0141 {
0142     memset(optval, 0, sizeof(*optval));
0143     optval->value = ULLONG_MAX;
0144     if (value != ULLONG_MAX)
0145         optval->value = value;
0146     else if (string)
0147         optval->string = string;
0148 
0149     if (extra && extra_len <= BOND_OPT_EXTRA_MAXLEN)
0150         memcpy(optval->extra, extra, extra_len);
0151 }
0152 #define bond_opt_initval(optval, value) __bond_opt_init(optval, NULL, value, NULL, 0)
0153 #define bond_opt_initstr(optval, str) __bond_opt_init(optval, str, ULLONG_MAX, NULL, 0)
0154 #define bond_opt_initextra(optval, extra, extra_len) \
0155     __bond_opt_init(optval, NULL, ULLONG_MAX, extra, extra_len)
0156 #define bond_opt_slave_initval(optval, slave_dev, value) \
0157     __bond_opt_init(optval, NULL, value, slave_dev, sizeof(struct net_device *))
0158 
0159 void bond_option_arp_ip_targets_clear(struct bonding *bond);
0160 #if IS_ENABLED(CONFIG_IPV6)
0161 void bond_option_ns_ip6_targets_clear(struct bonding *bond);
0162 #endif
0163 
0164 #endif /* _NET_BOND_OPTIONS_H */