Define new netlink attributes for rmnet mux_id and flags. These flags / mux_id were earlier using vlan flags / id respectively. The flag bits are also moved to uapi and are renamed with prefix RMNET_FLAG_*. Also add the rmnet policy to handle the new netlink attributes.
Unified · Split
| @@ -43,6 +43,11 @@ · 42 unmodified lines | |||
| 43 | 43 | ||
| 44 | /* Local Definitions and Declarations */ | 44 | /* Local Definitions and Declarations */ |
| 45 | 45 | ||
| 46 | static const struct nla_policy rmnet_policy[IFLA_RMNET_MAX + 1] = { | ||
| 47 | [IFLA_RMNET_MUX_ID] = { .type = NLA_U16 }, | ||
| 48 | [IFLA_RMNET_FLAGS] = { .len = sizeof(struct ifla_rmnet_flags) }, | ||
| 49 | }; | ||
| 50 | |||
| 46 | static int rmnet_is_real_dev_registered(const struct net_device *real_dev) | 51 | static int rmnet_is_real_dev_registered(const struct net_device *real_dev) |
| 47 | { | 52 | { |
| 48 | return rcu_access_pointer(real_dev->rx_handler) == rmnet_rx_handler; | 53 | return rcu_access_pointer(real_dev->rx_handler) == rmnet_rx_handler; |
| @@ -131,7 +136,7 @@ static int rmnet_newlink(struct net *src_net, struct net_device *dev, · 82 unmodified lines | |||
| 131 | struct nlattr *tb[], struct nlattr *data[], | 136 | struct nlattr *tb[], struct nlattr *data[], |
| 132 | struct netlink_ext_ack *extack) | 137 | struct netlink_ext_ack *extack) |
| 133 | { | 138 | { |
| 134 | u32 data_format = RMNET_INGRESS_FORMAT_DEAGGREGATION; | 139 | u32 data_format = RMNET_FLAGS_INGRESS_DEAGGREGATION; |
| 135 | struct net_device *real_dev; | 140 | struct net_device *real_dev; |
| 136 | int mode = RMNET_EPMODE_VND; | 141 | int mode = RMNET_EPMODE_VND; |
| 137 | struct rmnet_endpoint *ep; | 142 | struct rmnet_endpoint *ep; |
| @@ -143,14 +148,14 @@ static int rmnet_newlink(struct net *src_net, struct net_device *dev, · 5 unmodified lines | |||
| 143 | if (!real_dev || !dev) | 148 | if (!real_dev || !dev) |
| 144 | return -ENODEV; | 149 | return -ENODEV; |
| 145 | 150 | ||
| 146 | if (!data[IFLA_VLAN_ID]) | 151 | if (!data[IFLA_RMNET_MUX_ID]) |
| 147 | return -EINVAL; | 152 | return -EINVAL; |
| 148 | 153 | ||
| 149 | ep = kzalloc(sizeof(*ep), GFP_ATOMIC); | 154 | ep = kzalloc(sizeof(*ep), GFP_ATOMIC); |
| 150 | if (!ep) | 155 | if (!ep) |
| 151 | return -ENOMEM; | 156 | return -ENOMEM; |
| 152 | 157 | ||
| 153 | mux_id = nla_get_u16(data[IFLA_VLAN_ID]); | 158 | mux_id = nla_get_u16(data[IFLA_RMNET_MUX_ID]); |
| 154 | 159 | ||
| 155 | err = rmnet_register_real_device(real_dev); | 160 | err = rmnet_register_real_device(real_dev); |
| 156 | if (err) | 161 | if (err) |
| @@ -165,10 +170,10 @@ static int rmnet_newlink(struct net *src_net, struct net_device *dev, · 8 unmodified lines | |||
| 165 | 170 | ||
| 166 | hlist_add_head_rcu(&ep->hlnode, &port->muxed_ep[mux_id]); | 171 | hlist_add_head_rcu(&ep->hlnode, &port->muxed_ep[mux_id]); |
| 167 | 172 | ||
| 168 | if (data[IFLA_VLAN_FLAGS]) { | 173 | if (data[IFLA_RMNET_FLAGS]) { |
| 169 | struct ifla_vlan_flags *flags; | 174 | struct ifla_rmnet_flags *flags; |
| 170 | 175 | ||
| 171 | flags = nla_data(data[IFLA_VLAN_FLAGS]); | 176 | flags = nla_data(data[IFLA_RMNET_FLAGS]); |
| 172 | data_format = flags->flags & flags->mask; | 177 | data_format = flags->flags & flags->mask; |
| 173 | } | 178 | } |
| 174 | 179 | ||
| @@ -276,10 +281,10 @@ static int rmnet_rtnl_validate(struct nlattr *tb[], struct nlattr *data[], · 101 unmodified lines | |||
| 276 | { | 281 | { |
| 277 | u16 mux_id; | 282 | u16 mux_id; |
| 278 | 283 | ||
| 279 | if (!data || !data[IFLA_VLAN_ID]) | 284 | if (!data || !data[IFLA_RMNET_MUX_ID]) |
| 280 | return -EINVAL; | 285 | return -EINVAL; |
| 281 | 286 | ||
| 282 | mux_id = nla_get_u16(data[IFLA_VLAN_ID]); | 287 | mux_id = nla_get_u16(data[IFLA_RMNET_MUX_ID]); |
| 283 | if (mux_id > (RMNET_MAX_LOGICAL_EP - 1)) | 288 | if (mux_id > (RMNET_MAX_LOGICAL_EP - 1)) |
| 284 | return -ERANGE; | 289 | return -ERANGE; |
| 285 | 290 | ||
| @@ -304,8 +309,8 @@ static int rmnet_changelink(struct net_device *dev, struct nlattr *tb[], · 18 unmodified lines | |||
| 304 | 309 | ||
| 305 | port = rmnet_get_port_rtnl(real_dev); | 310 | port = rmnet_get_port_rtnl(real_dev); |
| 306 | 311 | ||
| 307 | if (data[IFLA_VLAN_ID]) { | 312 | if (data[IFLA_RMNET_MUX_ID]) { |
| 308 | mux_id = nla_get_u16(data[IFLA_VLAN_ID]); | 313 | mux_id = nla_get_u16(data[IFLA_RMNET_MUX_ID]); |
| 309 | ep = rmnet_get_endpoint(port, priv->mux_id); | 314 | ep = rmnet_get_endpoint(port, priv->mux_id); |
| 310 | 315 | ||
| 311 | hlist_del_init_rcu(&ep->hlnode); | 316 | hlist_del_init_rcu(&ep->hlnode); |
| @@ -315,10 +320,10 @@ static int rmnet_changelink(struct net_device *dev, struct nlattr *tb[], · 3 unmodified lines | |||
| 315 | priv->mux_id = mux_id; | 320 | priv->mux_id = mux_id; |
| 316 | } | 321 | } |
| 317 | 322 | ||
| 318 | if (data[IFLA_VLAN_FLAGS]) { | 323 | if (data[IFLA_RMNET_FLAGS]) { |
| 319 | struct ifla_vlan_flags *flags; | 324 | struct ifla_rmnet_flags *flags; |
| 320 | 325 | ||
| 321 | flags = nla_data(data[IFLA_VLAN_FLAGS]); | 326 | flags = nla_data(data[IFLA_RMNET_FLAGS]); |
| 322 | port->data_format = flags->flags & flags->mask; | 327 | port->data_format = flags->flags & flags->mask; |
| 323 | } | 328 | } |
| 324 | 329 | ||
| @@ -327,13 +332,16 @@ static int rmnet_changelink(struct net_device *dev, struct nlattr *tb[], · 2 unmodified lines | |||
| 327 | 332 | ||
| 328 | static size_t rmnet_get_size(const struct net_device *dev) | 333 | static size_t rmnet_get_size(const struct net_device *dev) |
| 329 | { | 334 | { |
| 330 | return nla_total_size(2) /* IFLA_VLAN_ID */ + | 335 | return |
| 331 | nla_total_size(sizeof(struct ifla_vlan_flags)); /* IFLA_VLAN_FLAGS */ | 336 | /* IFLA_RMNET_MUX_ID */ |
| 337 | nla_total_size(2) + | ||
| 338 | /* IFLA_RMNET_FLAGS */ | ||
| 339 | nla_total_size(sizeof(struct ifla_rmnet_flags)); | ||
| 332 | } | 340 | } |
| 333 | 341 | ||
| 334 | struct rtnl_link_ops rmnet_link_ops __read_mostly = { | 342 | struct rtnl_link_ops rmnet_link_ops __read_mostly = { |
| 335 | .kind = "rmnet", | 343 | .kind = "rmnet", |
| 336 | .maxtype = __IFLA_VLAN_MAX, | 344 | .maxtype = __IFLA_RMNET_MAX, |
| 337 | .priv_size = sizeof(struct rmnet_priv), | 345 | .priv_size = sizeof(struct rmnet_priv), |
| 338 | .setup = rmnet_vnd_setup, | 346 | .setup = rmnet_vnd_setup, |
| 339 | .validate = rmnet_rtnl_validate, | 347 | .validate = rmnet_rtnl_validate, |
| @@ -341,6 +349,7 @@ struct rtnl_link_ops rmnet_link_ops __read_mostly = { · 1 unmodified line | |||
| 341 | .dellink = rmnet_dellink, | 349 | .dellink = rmnet_dellink, |
| 342 | .get_size = rmnet_get_size, | 350 | .get_size = rmnet_get_size, |
| 343 | .changelink = rmnet_changelink, | 351 | .changelink = rmnet_changelink, |
| 352 | .policy = rmnet_policy, | ||
| 344 | }; | 353 | }; |
| 345 | 354 | ||
| 346 | /* Needs either rcu_read_lock() or rtnl lock */ | 355 | /* Needs either rcu_read_lock() or rtnl lock */ |
| @@ -70,7 +70,7 @@ __rmnet_map_ingress_handler(struct sk_buff *skb, · 69 unmodified lines | |||
| 70 | u8 mux_id; | 70 | u8 mux_id; |
| 71 | 71 | ||
| 72 | if (RMNET_MAP_GET_CD_BIT(skb)) { | 72 | if (RMNET_MAP_GET_CD_BIT(skb)) { |
| 73 | if (port->data_format & RMNET_INGRESS_FORMAT_MAP_COMMANDS) | 73 | if (port->data_format & RMNET_FLAGS_INGRESS_MAP_COMMANDS) |
| 74 | return rmnet_map_command(skb, port); | 74 | return rmnet_map_command(skb, port); |
| 75 | 75 | ||
| 76 | goto free_skb; | 76 | goto free_skb; |
| @@ -93,7 +93,7 @@ __rmnet_map_ingress_handler(struct sk_buff *skb, · 16 unmodified lines | |||
| 93 | skb_pull(skb, sizeof(struct rmnet_map_header)); | 93 | skb_pull(skb, sizeof(struct rmnet_map_header)); |
| 94 | rmnet_set_skb_proto(skb); | 94 | rmnet_set_skb_proto(skb); |
| 95 | 95 | ||
| 96 | if (port->data_format & RMNET_INGRESS_FORMAT_MAP_CKSUMV4) { | 96 | if (port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4) { |
| 97 | if (!rmnet_map_checksum_downlink_packet(skb, len + pad)) | 97 | if (!rmnet_map_checksum_downlink_packet(skb, len + pad)) |
| 98 | skb->ip_summed = CHECKSUM_UNNECESSARY; | 98 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 99 | } | 99 | } |
| @@ -121,7 +121,7 @@ rmnet_map_ingress_handler(struct sk_buff *skb, · 21 unmodified lines | |||
| 121 | skb_push(skb, ETH_HLEN); | 121 | skb_push(skb, ETH_HLEN); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | if (port->data_format & RMNET_INGRESS_FORMAT_DEAGGREGATION) { | 124 | if (port->data_format & RMNET_FLAGS_INGRESS_DEAGGREGATION) { |
| 125 | while ((skbn = rmnet_map_deaggregate(skb, port)) != NULL) | 125 | while ((skbn = rmnet_map_deaggregate(skb, port)) != NULL) |
| 126 | __rmnet_map_ingress_handler(skbn, port); | 126 | __rmnet_map_ingress_handler(skbn, port); |
| 127 | 127 | ||
| @@ -141,7 +141,7 @@ static int rmnet_map_egress_handler(struct sk_buff *skb, · 13 unmodified lines | |||
| 141 | additional_header_len = 0; | 141 | additional_header_len = 0; |
| 142 | required_headroom = sizeof(struct rmnet_map_header); | 142 | required_headroom = sizeof(struct rmnet_map_header); |
| 143 | 143 | ||
| 144 | if (port->data_format & RMNET_EGRESS_FORMAT_MAP_CKSUMV4) { | 144 | if (port->data_format & RMNET_FLAGS_EGRESS_MAP_CKSUMV4) { |
| 145 | additional_header_len = sizeof(struct rmnet_map_ul_csum_header); | 145 | additional_header_len = sizeof(struct rmnet_map_ul_csum_header); |
| 146 | required_headroom += additional_header_len; | 146 | required_headroom += additional_header_len; |
| 147 | } | 147 | } |
| @@ -151,7 +151,7 @@ static int rmnet_map_egress_handler(struct sk_buff *skb, · 3 unmodified lines | |||
| 151 | goto fail; | 151 | goto fail; |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | if (port->data_format & RMNET_EGRESS_FORMAT_MAP_CKSUMV4) | 154 | if (port->data_format & RMNET_FLAGS_EGRESS_MAP_CKSUMV4) |
| 155 | rmnet_map_checksum_uplink_packet(skb, orig_dev); | 155 | rmnet_map_checksum_uplink_packet(skb, orig_dev); |
| 156 | 156 | ||
| 157 | map_header = rmnet_map_add_map_header(skb, additional_header_len, 0); | 157 | map_header = rmnet_map_add_map_header(skb, additional_header_len, 0); |
| @@ -69,7 +69,7 @@ static void rmnet_map_send_ack(struct sk_buff *skb, · 68 unmodified lines | |||
| 69 | struct rmnet_map_control_command *cmd; | 69 | struct rmnet_map_control_command *cmd; |
| 70 | int xmit_status; | 70 | int xmit_status; |
| 71 | 71 | ||
| 72 | if (port->data_format & RMNET_INGRESS_FORMAT_MAP_CKSUMV4) { | 72 | if (port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4) { |
| 73 | if (skb->len < sizeof(struct rmnet_map_header) + | 73 | if (skb->len < sizeof(struct rmnet_map_header) + |
| 74 | RMNET_MAP_GET_LENGTH(skb) + | 74 | RMNET_MAP_GET_LENGTH(skb) + |
| 75 | sizeof(struct rmnet_map_dl_csum_trailer)) { | 75 | sizeof(struct rmnet_map_dl_csum_trailer)) { |
| @@ -309,7 +309,7 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb, · 308 unmodified lines | |||
| 309 | maph = (struct rmnet_map_header *)skb->data; | 309 | maph = (struct rmnet_map_header *)skb->data; |
| 310 | packet_len = ntohs(maph->pkt_len) + sizeof(struct rmnet_map_header); | 310 | packet_len = ntohs(maph->pkt_len) + sizeof(struct rmnet_map_header); |
| 311 | 311 | ||
| 312 | if (port->data_format & RMNET_INGRESS_FORMAT_MAP_CKSUMV4) | 312 | if (port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4) |
| 313 | packet_len += sizeof(struct rmnet_map_dl_csum_trailer); | 313 | packet_len += sizeof(struct rmnet_map_dl_csum_trailer); |
| 314 | 314 | ||
| 315 | if (((int)skb->len - (int)packet_len) < 0) | 315 | if (((int)skb->len - (int)packet_len) < 0) |
| @@ -18,12 +18,6 @@ · 17 unmodified lines | |||
| 18 | #define RMNET_NEEDED_HEADROOM 16 | 18 | #define RMNET_NEEDED_HEADROOM 16 |
| 19 | #define RMNET_TX_QUEUE_LEN 1000 | 19 | #define RMNET_TX_QUEUE_LEN 1000 |
| 20 | 20 | ||
| 21 | /* Constants */ | ||
| 22 | #define RMNET_INGRESS_FORMAT_DEAGGREGATION BIT(0) | ||
| 23 | #define RMNET_INGRESS_FORMAT_MAP_COMMANDS BIT(1) | ||
| 24 | #define RMNET_INGRESS_FORMAT_MAP_CKSUMV4 BIT(2) | ||
| 25 | #define RMNET_EGRESS_FORMAT_MAP_CKSUMV4 BIT(3) | ||
| 26 | |||
| 27 | /* Replace skb->dev to a virtual rmnet device and pass up the stack */ | 21 | /* Replace skb->dev to a virtual rmnet device and pass up the stack */ |
| 28 | #define RMNET_EPMODE_VND (1) | 22 | #define RMNET_EPMODE_VND (1) |
| 29 | /* Pass the frame directly to another device with dev_queue_xmit() */ | 23 | /* Pass the frame directly to another device with dev_queue_xmit() */ |
| @@ -959,4 +959,25 @@ enum { · 958 unmodified lines | |||
| 959 | 959 | ||
| 960 | #define IFLA_TUN_MAX (__IFLA_TUN_MAX - 1) | 960 | #define IFLA_TUN_MAX (__IFLA_TUN_MAX - 1) |
| 961 | 961 | ||
| 962 | /* rmnet section */ | ||
| 963 | |||
| 964 | #define RMNET_FLAGS_INGRESS_DEAGGREGATION (1U << 0) | ||
| 965 | #define RMNET_FLAGS_INGRESS_MAP_COMMANDS (1U << 1) | ||
| 966 | #define RMNET_FLAGS_INGRESS_MAP_CKSUMV4 (1U << 2) | ||
| 967 | #define RMNET_FLAGS_EGRESS_MAP_CKSUMV4 (1U << 3) | ||
| 968 | |||
| 969 | enum { | ||
| 970 | IFLA_RMNET_UNSPEC, | ||
| 971 | IFLA_RMNET_MUX_ID, | ||
| 972 | IFLA_RMNET_FLAGS, | ||
| 973 | __IFLA_RMNET_MAX, | ||
| 974 | }; | ||
| 975 | |||
| 976 | #define IFLA_RMNET_MAX (__IFLA_RMNET_MAX - 1) | ||
| 977 | |||
| 978 | struct ifla_rmnet_flags { | ||
| 979 | __u32 flags; | ||
| 980 | __u32 mask; | ||
| 981 | }; | ||
| 982 | |||
| 962 | #endif /* _UAPI_LINUX_IF_LINK_H */ | 983 | #endif /* _UAPI_LINUX_IF_LINK_H */ |