^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * net/dccp/diag.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * An implementation of the DCCP protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Arnaldo Carvalho de Melo <acme@mandriva.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/inet_diag.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "ccid.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "dccp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static void dccp_get_info(struct sock *sk, struct tcp_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct dccp_sock *dp = dccp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) const struct inet_connection_sock *icsk = inet_csk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) memset(info, 0, sizeof(*info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) info->tcpi_state = sk->sk_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) info->tcpi_retransmits = icsk->icsk_retransmits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) info->tcpi_probes = icsk->icsk_probes_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) info->tcpi_backoff = icsk->icsk_backoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) info->tcpi_pmtu = icsk->icsk_pmtu_cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) if (dp->dccps_hc_rx_ackvec != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) info->tcpi_options |= TCPI_OPT_SACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) if (dp->dccps_hc_rx_ccid != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) ccid_hc_rx_get_info(dp->dccps_hc_rx_ccid, sk, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if (dp->dccps_hc_tx_ccid != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ccid_hc_tx_get_info(dp->dccps_hc_tx_ccid, sk, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static void dccp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) void *_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) r->idiag_rqueue = r->idiag_wqueue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (_info != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) dccp_get_info(sk, _info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static void dccp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) const struct inet_diag_req_v2 *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) inet_diag_dump_icsk(&dccp_hashinfo, skb, cb, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static int dccp_diag_dump_one(struct netlink_callback *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) const struct inet_diag_req_v2 *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return inet_diag_dump_one_icsk(&dccp_hashinfo, cb, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static const struct inet_diag_handler dccp_diag_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .dump = dccp_diag_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .dump_one = dccp_diag_dump_one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .idiag_get_info = dccp_diag_get_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .idiag_type = IPPROTO_DCCP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .idiag_info_size = sizeof(struct tcp_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static int __init dccp_diag_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return inet_diag_register(&dccp_diag_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static void __exit dccp_diag_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) inet_diag_unregister(&dccp_diag_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) module_init(dccp_diag_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) module_exit(dccp_diag_fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) MODULE_AUTHOR("Arnaldo Carvalho de Melo <acme@mandriva.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) MODULE_DESCRIPTION("DCCP inet_diag handler");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 2-33 /* AF_INET - IPPROTO_DCCP */);