@@ -897,6 +897,130 @@ static void batadv_v_gw_print(struct batadv_priv *bat_priv,
897
897
seq_puts (seq , "No gateways in range ...\n" );
898
898
}
899
899
900
+ /**
901
+ * batadv_v_gw_dump_entry - Dump a gateway into a message
902
+ * @msg: Netlink message to dump into
903
+ * @portid: Port making netlink request
904
+ * @seq: Sequence number of netlink message
905
+ * @bat_priv: The bat priv with all the soft interface information
906
+ * @gw_node: Gateway to be dumped
907
+ *
908
+ * Return: Error code, or 0 on success
909
+ */
910
+ static int batadv_v_gw_dump_entry (struct sk_buff * msg , u32 portid , u32 seq ,
911
+ struct batadv_priv * bat_priv ,
912
+ struct batadv_gw_node * gw_node )
913
+ {
914
+ struct batadv_neigh_ifinfo * router_ifinfo = NULL ;
915
+ struct batadv_neigh_node * router ;
916
+ struct batadv_gw_node * curr_gw ;
917
+ int ret = - EINVAL ;
918
+ void * hdr ;
919
+
920
+ router = batadv_orig_router_get (gw_node -> orig_node , BATADV_IF_DEFAULT );
921
+ if (!router )
922
+ goto out ;
923
+
924
+ router_ifinfo = batadv_neigh_ifinfo_get (router , BATADV_IF_DEFAULT );
925
+ if (!router_ifinfo )
926
+ goto out ;
927
+
928
+ curr_gw = batadv_gw_get_selected_gw_node (bat_priv );
929
+
930
+ hdr = genlmsg_put (msg , portid , seq , & batadv_netlink_family ,
931
+ NLM_F_MULTI , BATADV_CMD_GET_GATEWAYS );
932
+ if (!hdr ) {
933
+ ret = - ENOBUFS ;
934
+ goto out ;
935
+ }
936
+
937
+ ret = - EMSGSIZE ;
938
+
939
+ if (curr_gw == gw_node ) {
940
+ if (nla_put_flag (msg , BATADV_ATTR_FLAG_BEST )) {
941
+ genlmsg_cancel (msg , hdr );
942
+ goto out ;
943
+ }
944
+ }
945
+
946
+ if (nla_put (msg , BATADV_ATTR_ORIG_ADDRESS , ETH_ALEN ,
947
+ gw_node -> orig_node -> orig )) {
948
+ genlmsg_cancel (msg , hdr );
949
+ goto out ;
950
+ }
951
+
952
+ if (nla_put_u32 (msg , BATADV_ATTR_THROUGHPUT ,
953
+ router_ifinfo -> bat_v .throughput )) {
954
+ genlmsg_cancel (msg , hdr );
955
+ goto out ;
956
+ }
957
+
958
+ if (nla_put (msg , BATADV_ATTR_ROUTER , ETH_ALEN , router -> addr )) {
959
+ genlmsg_cancel (msg , hdr );
960
+ goto out ;
961
+ }
962
+
963
+ if (nla_put_string (msg , BATADV_ATTR_HARD_IFNAME ,
964
+ router -> if_incoming -> net_dev -> name )) {
965
+ genlmsg_cancel (msg , hdr );
966
+ goto out ;
967
+ }
968
+
969
+ if (nla_put_u32 (msg , BATADV_ATTR_BANDWIDTH_DOWN ,
970
+ gw_node -> bandwidth_down )) {
971
+ genlmsg_cancel (msg , hdr );
972
+ goto out ;
973
+ }
974
+
975
+ if (nla_put_u32 (msg , BATADV_ATTR_BANDWIDTH_UP , gw_node -> bandwidth_up )) {
976
+ genlmsg_cancel (msg , hdr );
977
+ goto out ;
978
+ }
979
+
980
+ genlmsg_end (msg , hdr );
981
+ ret = 0 ;
982
+
983
+ out :
984
+ if (router_ifinfo )
985
+ batadv_neigh_ifinfo_put (router_ifinfo );
986
+ if (router )
987
+ batadv_neigh_node_put (router );
988
+ return ret ;
989
+ }
990
+
991
+ /**
992
+ * batadv_v_gw_dump - Dump gateways into a message
993
+ * @msg: Netlink message to dump into
994
+ * @cb: Control block containing additional options
995
+ * @bat_priv: The bat priv with all the soft interface information
996
+ */
997
+ static void batadv_v_gw_dump (struct sk_buff * msg , struct netlink_callback * cb ,
998
+ struct batadv_priv * bat_priv )
999
+ {
1000
+ int portid = NETLINK_CB (cb -> skb ).portid ;
1001
+ struct batadv_gw_node * gw_node ;
1002
+ int idx_skip = cb -> args [0 ];
1003
+ int idx = 0 ;
1004
+
1005
+ rcu_read_lock ();
1006
+ hlist_for_each_entry_rcu (gw_node , & bat_priv -> gw .list , list ) {
1007
+ if (idx ++ < idx_skip )
1008
+ continue ;
1009
+
1010
+ if (batadv_v_gw_dump_entry (msg , portid , cb -> nlh -> nlmsg_seq ,
1011
+ bat_priv , gw_node )) {
1012
+ idx_skip = idx - 1 ;
1013
+ goto unlock ;
1014
+ }
1015
+ }
1016
+
1017
+ idx_skip = idx ;
1018
+ unlock :
1019
+ rcu_read_unlock ();
1020
+
1021
+ cb -> args [0 ] = idx_skip ;
1022
+ }
1023
+
900
1024
static struct batadv_algo_ops batadv_batman_v __read_mostly = {
901
1025
.name = "BATMAN_V" ,
902
1026
.iface = {
@@ -923,6 +1047,7 @@ static struct batadv_algo_ops batadv_batman_v __read_mostly = {
923
1047
.get_best_gw_node = batadv_v_gw_get_best_gw_node ,
924
1048
.is_eligible = batadv_v_gw_is_eligible ,
925
1049
.print = batadv_v_gw_print ,
1050
+ .dump = batadv_v_gw_dump ,
926
1051
},
927
1052
};
928
1053
0 commit comments