--- zzzz-none-000/linux-4.1.38/net/netfilter/nf_conntrack_sip.c 2017-01-18 18:48:06.000000000 +0000 +++ bcm63-7582-715/linux-4.1.38/net/netfilter/nf_conntrack_sip.c 2020-11-25 10:06:48.000000000 +0000 @@ -25,6 +25,10 @@ #include #include #include +#if defined(CONFIG_BCM_KF_NETFILTER_SIP) +#include +#include +#endif MODULE_LICENSE("GPL"); MODULE_AUTHOR("Christian Hentschel "); @@ -839,6 +843,45 @@ spin_unlock_bh(&nf_conntrack_expect_lock); } +#if defined(CONFIG_BCM_KF_NETFILTER_SIP) +static void bcm_sip_expectfn(struct nf_conn *ct, + struct nf_conntrack_expect *exp) +{ + iqos_add_L4port(IPPROTO_UDP, + ntohs(ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u.udp.port), + IQOS_ENT_DYN, IQOS_PRIO_HIGH ); + iqos_add_L4port( IPPROTO_UDP, + ntohs(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u.udp.port), + IQOS_ENT_DYN, + IQOS_PRIO_HIGH ); + set_bit(IPS_IQOS_BIT, &ct->status); +} +static inline unsigned int bcm_nf_sip_sdp_media(struct sk_buff *skb, unsigned int protoff, + unsigned int dataoff, + const char **dptr, unsigned int *datalen, + struct nf_conntrack_expect *rtp_exp, + struct nf_conntrack_expect *rtcp_exp, + unsigned int mediaoff, + unsigned int medialen, + union nf_inet_addr *rtp_addr) +{ + /* even when NAT is not present we need to call expectfn to add RTP&RTCP + * ports to IQ table + */ + rtp_exp->expectfn = bcm_sip_expectfn; + rtcp_exp->expectfn = bcm_sip_expectfn; + + if (nf_ct_expect_related(rtp_exp) == 0) { + if (nf_ct_expect_related(rtcp_exp) != 0) + nf_ct_unexpect_related(rtp_exp); + else{ + return NF_ACCEPT; + } + } + return NF_DROP; +} +#endif + static int set_expected_rtp_rtcp(struct sk_buff *skb, unsigned int protoff, unsigned int dataoff, const char **dptr, unsigned int *datalen, @@ -943,12 +986,19 @@ datalen, rtp_exp, rtcp_exp, mediaoff, medialen, daddr); else { +#if defined(CONFIG_BCM_KF_NETFILTER_SIP) + ret = bcm_nf_sip_sdp_media(skb, protoff, dataoff, dptr, + datalen, rtp_exp, rtcp_exp, + mediaoff, medialen, daddr); +#else if (nf_ct_expect_related(rtp_exp) == 0) { if (nf_ct_expect_related(rtcp_exp) != 0) nf_ct_unexpect_related(rtp_exp); else ret = NF_ACCEPT; } +#endif + } nf_ct_expect_put(rtcp_exp); err2: @@ -1165,6 +1215,32 @@ { enum ip_conntrack_info ctinfo; struct nf_conn *ct = nf_ct_get(skb, &ctinfo); +#if defined(CONFIG_BCM_KF_NETFILTER_SIP) + struct nf_conn *child; + + /* cdrouter_sip_60 */ + list_for_each_entry(child, &ct->derived_connections, derived_list) { +#if defined(CONFIG_BCM_KF_BLOG) && defined(CONFIG_BLOG) + blog_lock(); + if ((child->blog_key[IP_CT_DIR_ORIGINAL] != BLOG_KEY_FC_INVALID) + || (child->blog_key[IP_CT_DIR_REPLY] != BLOG_KEY_FC_INVALID)) { + /* remove flow from flow cache */ + blog_notify(DESTROY_FLOWTRACK, (void*)child, + (uint32_t)child->blog_key[IP_CT_DIR_ORIGINAL], + (uint32_t)child->blog_key[IP_CT_DIR_REPLY]); + + /* Safe: In case blog client does not set key + * to BLOG_KEY_FC_INVALID explicilty */ + child->blog_key[IP_CT_DIR_ORIGINAL] = BLOG_KEY_FC_INVALID; + child->blog_key[IP_CT_DIR_REPLY] = BLOG_KEY_FC_INVALID; + set_bit(IPS_BLOG_BIT, &child->status); /* Enable conntrack blogging */ + } + blog_unlock(); +#endif + child->derived_timeout = 5*HZ; + nf_ct_refresh(child, skb, 5*HZ); + } +#endif flush_expectations(ct, true); return NF_ACCEPT; @@ -1355,6 +1431,9 @@ SIP_HANDLER("ACK", process_sdp, NULL), SIP_HANDLER("PRACK", process_sdp, process_prack_response), SIP_HANDLER("BYE", process_bye_request, NULL), +#if defined(CONFIG_BCM_KF_NETFILTER_SIP) + SIP_HANDLER("CANCEL", process_bye_request, NULL), /*cdrouter_sip_62*/ +#endif SIP_HANDLER("REGISTER", process_register_request, process_register_response), }; @@ -1622,6 +1701,11 @@ continue; nf_conntrack_helper_unregister(&sip[i][j]); } +#if defined(CONFIG_BCM_KF_NETFILTER_SIP) + /* unregister the SIP ports with ingress QoS classifier */ + iqos_rem_L4port( IPPROTO_UDP, ports[i], IQOS_ENT_STAT ); + iqos_rem_L4port( IPPROTO_TCP, ports[i], IQOS_ENT_STAT ); +#endif } } @@ -1672,9 +1756,15 @@ return ret; } } +#if defined(CONFIG_BCM_KF_NETFILTER_SIP) + /* register the SIP ports with ingress QoS classifier */ + iqos_add_L4port( IPPROTO_UDP, ports[i], IQOS_ENT_STAT, IQOS_PRIO_HIGH ); + iqos_add_L4port( IPPROTO_TCP, ports[i], IQOS_ENT_STAT, IQOS_PRIO_HIGH ); +#endif } return 0; } module_init(nf_conntrack_sip_init); module_exit(nf_conntrack_sip_fini); +