Guest User

Untitled

a guest
Mar 23rd, 2014
590
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/nf_nat_rtsp.c b/nf_nat_rtsp.c
  2. index 6be8346..bc60b71 100644
  3. --- a/nf_nat_rtsp.c
  4. +++ b/nf_nat_rtsp.c
  5. @@ -67,6 +67,8 @@ static char* destaction = NULL;
  6. static u_int32_t extip = 0;
  7. static int dstact = 0;
  8.  
  9. +static char *rtsp_buffer;
  10. +
  11. static void nf_nat_rtsp_expected(struct nf_conn* ct, struct nf_conntrack_expect *exp);
  12.  
  13. MODULE_AUTHOR("Tom Marshall <tmarshall at real.com>");
  14. @@ -82,13 +84,29 @@ MODULE_PARM_DESC(destaction, "Action for destination parameter (auto/strip/none)
  15. /*** helper functions ***/
  16.  
  17. static void
  18. -get_skb_tcpdata(struct sk_buff* skb, char** pptcpdata, uint* ptcpdatalen)
  19. +get_skb_tcpdata(struct sk_buff* skb, char** pptcpdata, uint* ptcpdatalen, uint protoff)
  20. {
  21. - struct iphdr* iph = ip_hdr(skb);
  22. - struct tcphdr* tcph = (void *)iph + ip_hdrlen(skb);
  23. + struct tcphdr _tcph, *th;
  24. + int datalen, dataoff;
  25. +
  26. + /* Not whole TCP header? */
  27. + th = skb_header_pointer(skb, protoff, sizeof(_tcph), &_tcph);
  28. + if (!th)
  29. + {
  30. + *ptcpdatalen = 0;
  31. + return;
  32. + }
  33. + /* No data ? */
  34. + dataoff = protoff + th->doff*4;
  35. + if (dataoff >= skb->len)
  36. + {
  37. + *ptcpdatalen = 0;
  38. + return;
  39. + }
  40. + datalen = skb->len - dataoff;
  41.  
  42. - *pptcpdata = (char*)tcph + tcph->doff*4;
  43. - *ptcpdatalen = ((char*)skb_transport_header(skb) + skb->len) - *pptcpdata;
  44. + *pptcpdata = skb_header_pointer(skb, dataoff, datalen, rtsp_buffer);
  45. + *ptcpdatalen = datalen;
  46. }
  47.  
  48. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  49. @@ -164,7 +182,7 @@ rtsp_mangle_tran(enum ip_conntrack_info ctinfo,
  50. uint extaddrlen;
  51. int is_stun;
  52.  
  53. - get_skb_tcpdata(skb, &ptcp, &tcplen);
  54. + get_skb_tcpdata(skb, &ptcp, &tcplen, protoff);
  55. ptran = ptcp+tranoff;
  56.  
  57. if (tranoff+tranlen > tcplen || tcplen-tranoff < tranlen ||
  58. @@ -325,7 +343,7 @@ rtsp_mangle_tran(enum ip_conntrack_info ctinfo,
  59. nf_ct_unexpect_related(rtcp_exp);
  60. return 0;
  61. }
  62. - get_skb_tcpdata(skb, &ptcp, &tcplen);
  63. + get_skb_tcpdata(skb, &ptcp, &tcplen, protoff);
  64. ptran = ptcp+tranoff;
  65. tranlen -= diff;
  66. nextparamoff -= diff;
  67. @@ -395,7 +413,7 @@ rtsp_mangle_tran(enum ip_conntrack_info ctinfo,
  68. nf_ct_unexpect_related(rtcp_exp);
  69. return 0;
  70. }
  71. - get_skb_tcpdata(skb, &ptcp, &tcplen);
  72. + get_skb_tcpdata(skb, &ptcp, &tcplen, protoff);
  73. ptran = ptcp+tranoff;
  74. tranlen -= diff;
  75. nextparamoff -= diff;
  76. @@ -439,7 +457,7 @@ help_out(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
  77. //struct iphdr* iph = (struct iphdr*)(*pskb)->nh.iph;
  78. //struct tcphdr* tcph = (struct tcphdr*)((void*)iph + iph->ihl*4);
  79.  
  80. - get_skb_tcpdata(skb, &ptcp, &tcplen);
  81. + get_skb_tcpdata(skb, &ptcp, &tcplen, protoff);
  82. hdrsoff = matchoff;//exp->seq - ntohl(tcph->seq);
  83. hdrslen = matchlen;
  84. off = hdrsoff;
  85. @@ -486,7 +504,7 @@ help_out(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
  86. rtcp_exp->saved_proto.udp.port = htons(prtspexp->hiport);
  87. rtcp_exp->dir = !dir;
  88. }
  89. - get_skb_tcpdata(skb, &ptcp, &tcplen);
  90. + get_skb_tcpdata(skb, &ptcp, &tcplen, protoff);
  91. hdrslen -= (oldtcplen-tcplen);
  92. off -= (oldtcplen-tcplen);
  93. lineoff -= (oldtcplen-tcplen);
  94. @@ -587,6 +605,7 @@ static void __exit fini(void)
  95. {
  96. rcu_assign_pointer(nf_nat_rtsp_hook, NULL);
  97. synchronize_net();
  98. + kfree(rtsp_buffer);
  99. }
  100.  
  101. static int __init init(void)
  102. @@ -610,6 +629,10 @@ static int __init init(void)
  103. dstact = DSTACT_NONE;
  104. }
  105.  
  106. + rtsp_buffer = kmalloc(65536, GFP_KERNEL);
  107. + if (!rtsp_buffer)
  108. + return -ENOMEM;
  109. +
  110. return 0;
  111. }
RAW Paste Data