options.c (1b1a6ef597c7f662da847499d02ad519c1a8b1b3) | options.c (761c124ed9698581e88d7babb9001401724435dd) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* Multipath TCP 3 * 4 * Copyright (c) 2017 - 2019, Intel Corporation. 5 */ 6 7#define pr_fmt(fmt) "MPTCP: " fmt 8 --- 569 unchanged lines hidden (view full) --- 578 ack_size += TCPOLEN_MPTCP_DSS_BASE; 579 580 dss_size += ack_size; 581 582 *size = ALIGN(dss_size, 4); 583 return true; 584} 585 | 1// SPDX-License-Identifier: GPL-2.0 2/* Multipath TCP 3 * 4 * Copyright (c) 2017 - 2019, Intel Corporation. 5 */ 6 7#define pr_fmt(fmt) "MPTCP: " fmt 8 --- 569 unchanged lines hidden (view full) --- 578 ack_size += TCPOLEN_MPTCP_DSS_BASE; 579 580 dss_size += ack_size; 581 582 *size = ALIGN(dss_size, 4); 583 return true; 584} 585 |
586static u64 add_addr_generate_hmac(u64 key1, u64 key2, u8 addr_id, 587 struct in_addr *addr, u16 port) | 586static u64 add_addr_generate_hmac(u64 key1, u64 key2, 587 struct mptcp_addr_info *addr) |
588{ | 588{ |
589 u16 port = ntohs(addr->port); |
|
589 u8 hmac[SHA256_DIGEST_SIZE]; | 590 u8 hmac[SHA256_DIGEST_SIZE]; |
590 u8 msg[7]; | 591 u8 msg[19]; 592 int i = 0; |
591 | 593 |
592 msg[0] = addr_id; 593 memcpy(&msg[1], &addr->s_addr, 4); 594 msg[5] = port >> 8; 595 msg[6] = port & 0xFF; 596 597 mptcp_crypto_hmac_sha(key1, key2, msg, 7, hmac); 598 599 return get_unaligned_be64(&hmac[SHA256_DIGEST_SIZE - sizeof(u64)]); 600} 601 | 594 msg[i++] = addr->id; 595 if (addr->family == AF_INET) { 596 memcpy(&msg[i], &addr->addr.s_addr, 4); 597 i += 4; 598 } |
602#if IS_ENABLED(CONFIG_MPTCP_IPV6) | 599#if IS_ENABLED(CONFIG_MPTCP_IPV6) |
603static u64 add_addr6_generate_hmac(u64 key1, u64 key2, u8 addr_id, 604 struct in6_addr *addr, u16 port) 605{ 606 u8 hmac[SHA256_DIGEST_SIZE]; 607 u8 msg[19]; | 600 else if (addr->family == AF_INET6) { 601 memcpy(&msg[i], &addr->addr6.s6_addr, 16); 602 i += 16; 603 } 604#endif 605 msg[i++] = port >> 8; 606 msg[i++] = port & 0xFF; |
608 | 607 |
609 msg[0] = addr_id; 610 memcpy(&msg[1], &addr->s6_addr, 16); 611 msg[17] = port >> 8; 612 msg[18] = port & 0xFF; | 608 mptcp_crypto_hmac_sha(key1, key2, msg, i, hmac); |
613 | 609 |
614 mptcp_crypto_hmac_sha(key1, key2, msg, 19, hmac); 615 | |
616 return get_unaligned_be64(&hmac[SHA256_DIGEST_SIZE - sizeof(u64)]); 617} | 610 return get_unaligned_be64(&hmac[SHA256_DIGEST_SIZE - sizeof(u64)]); 611} |
618#endif | |
619 620static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *skb, 621 unsigned int *size, 622 unsigned int remaining, 623 struct mptcp_out_options *opts) 624{ 625 struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); 626 struct mptcp_sock *msk = mptcp_sk(subflow->conn); --- 21 unchanged lines hidden (view full) --- 648 len = mptcp_add_addr_len(opts->addr.family, echo, port); 649 if (remaining < len) 650 return false; 651 652 *size = len; 653 if (drop_other_suboptions) 654 *size -= opt_size; 655 opts->suboptions |= OPTION_MPTCP_ADD_ADDR; | 612 613static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *skb, 614 unsigned int *size, 615 unsigned int remaining, 616 struct mptcp_out_options *opts) 617{ 618 struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); 619 struct mptcp_sock *msk = mptcp_sk(subflow->conn); --- 21 unchanged lines hidden (view full) --- 641 len = mptcp_add_addr_len(opts->addr.family, echo, port); 642 if (remaining < len) 643 return false; 644 645 *size = len; 646 if (drop_other_suboptions) 647 *size -= opt_size; 648 opts->suboptions |= OPTION_MPTCP_ADD_ADDR; |
656 if (opts->addr.family == AF_INET) { 657 if (!echo) { 658 opts->ahmac = add_addr_generate_hmac(msk->local_key, 659 msk->remote_key, 660 opts->addr.id, 661 &opts->addr.addr, 662 ntohs(opts->addr.port)); 663 } | 649 if (!echo) { 650 opts->ahmac = add_addr_generate_hmac(msk->local_key, 651 msk->remote_key, 652 &opts->addr); |
664 } | 653 } |
665#if IS_ENABLED(CONFIG_MPTCP_IPV6) 666 else if (opts->addr.family == AF_INET6) { 667 if (!echo) { 668 opts->ahmac = add_addr6_generate_hmac(msk->local_key, 669 msk->remote_key, 670 opts->addr.id, 671 &opts->addr.addr6, 672 ntohs(opts->addr.port)); 673 } 674 } 675#endif | |
676 pr_debug("addr_id=%d, ahmac=%llu, echo=%d, port=%d", 677 opts->addr.id, opts->ahmac, echo, ntohs(opts->addr.port)); 678 679 return true; 680} 681 682static bool mptcp_established_options_rm_addr(struct sock *sk, 683 unsigned int *size, --- 302 unchanged lines hidden (view full) --- 986static bool add_addr_hmac_valid(struct mptcp_sock *msk, 987 struct mptcp_options_received *mp_opt) 988{ 989 u64 hmac = 0; 990 991 if (mp_opt->echo) 992 return true; 993 | 654 pr_debug("addr_id=%d, ahmac=%llu, echo=%d, port=%d", 655 opts->addr.id, opts->ahmac, echo, ntohs(opts->addr.port)); 656 657 return true; 658} 659 660static bool mptcp_established_options_rm_addr(struct sock *sk, 661 unsigned int *size, --- 302 unchanged lines hidden (view full) --- 964static bool add_addr_hmac_valid(struct mptcp_sock *msk, 965 struct mptcp_options_received *mp_opt) 966{ 967 u64 hmac = 0; 968 969 if (mp_opt->echo) 970 return true; 971 |
994 if (mp_opt->addr.family == AF_INET) 995 hmac = add_addr_generate_hmac(msk->remote_key, 996 msk->local_key, 997 mp_opt->addr.id, &mp_opt->addr.addr, 998 ntohs(mp_opt->addr.port)); 999#if IS_ENABLED(CONFIG_MPTCP_IPV6) 1000 else 1001 hmac = add_addr6_generate_hmac(msk->remote_key, 1002 msk->local_key, 1003 mp_opt->addr.id, &mp_opt->addr.addr6, 1004 ntohs(mp_opt->addr.port)); 1005#endif | 972 hmac = add_addr_generate_hmac(msk->remote_key, 973 msk->local_key, 974 &mp_opt->addr); |
1006 1007 pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n", 1008 msk, (unsigned long long)hmac, 1009 (unsigned long long)mp_opt->ahmac); 1010 1011 return hmac == mp_opt->ahmac; 1012} 1013 --- 363 unchanged lines hidden --- | 975 976 pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n", 977 msk, (unsigned long long)hmac, 978 (unsigned long long)mp_opt->ahmac); 979 980 return hmac == mp_opt->ahmac; 981} 982 --- 363 unchanged lines hidden --- |