2 * Simple RCMD transparent proxy for in-kernel use. For use with the NAT
6 #if SOLARIS && defined(_KERNEL)
7 extern kmutex_t ipf_rw;
10 #define isdigit(x) ((x) >= '0' && (x) <= '9')
12 #define IPF_RCMD_PROXY
15 int ippr_rcmd_init __P((void));
16 int ippr_rcmd_new __P((fr_info_t *, ip_t *, ap_session_t *, nat_t *));
17 int ippr_rcmd_out __P((fr_info_t *, ip_t *, ap_session_t *, nat_t *));
18 u_short ipf_rcmd_atoi __P((char *));
19 int ippr_rcmd_portmsg __P((fr_info_t *, ip_t *, ap_session_t *, nat_t *));
21 static frentry_t rcmdfr;
25 * RCMD application proxy initialization.
29 bzero((char *)&rcmdfr, sizeof(rcmdfr));
31 rcmdfr.fr_flags = FR_INQUE|FR_PASS|FR_QUICK|FR_KEEPSTATE;
37 * Setup for a new RCMD proxy.
39 int ippr_rcmd_new(fin, ip, aps, nat)
45 tcphdr_t *tcp = (tcphdr_t *)fin->fin_dp;
47 aps->aps_psiz = sizeof(u_32_t);
48 KMALLOCS(aps->aps_data, u_32_t *, sizeof(u_32_t));
49 if (aps->aps_data == NULL)
51 *(u_32_t *)aps->aps_data = 0;
52 aps->aps_sport = tcp->th_sport;
53 aps->aps_dport = tcp->th_dport;
59 * ipf_rcmd_atoi - implement a simple version of atoi
61 u_short ipf_rcmd_atoi(ptr)
64 register char *s = ptr, c;
65 register u_short i = 0;
67 while ((c = *s++) && isdigit(c)) {
75 int ippr_rcmd_portmsg(fin, ip, aps, nat)
85 tcphdr_t *tcp, tcph, *tcp2 = &tcph;
93 tcp = (tcphdr_t *)fin->fin_dp;
94 off = (ip->ip_hl << 2) + (tcp->th_off << 2);
95 m = *(mb_t **)fin->fin_mp;
100 dlen = msgdsize(m) - off;
101 bzero(portbuf, sizeof(portbuf));
102 copyout_mblk(m, off, MIN(sizeof(portbuf), dlen), portbuf);
104 dlen = mbufchainlen(m) - off;
105 bzero(portbuf, sizeof(portbuf));
106 m_copydata(m, off, MIN(sizeof(portbuf), dlen), portbuf);
108 if ((*(u_32_t *)aps->aps_data != 0) &&
109 (tcp->th_seq != *(u_32_t *)aps->aps_data))
112 portbuf[sizeof(portbuf) - 1] = '\0';
114 sp = ipf_rcmd_atoi(s);
119 * Add skeleton NAT entry for connection which will come back the
123 dp = htons(fin->fin_data[1]);
124 ipn = nat_outlookup(fin->fin_ifp, IPN_TCP, nat->nat_p, nat->nat_inip,
125 ip->ip_dst, (dp << 16) | sp);
127 bcopy((char *)fin, (char *)&fi, sizeof(fi));
128 bzero((char *)tcp2, sizeof(*tcp2));
129 tcp2->th_win = htons(8192);
131 tcp2->th_dport = 0; /* XXX - don't specify remote port */
132 fi.fin_data[0] = ntohs(sp);
134 fi.fin_dp = (char *)tcp2;
136 ip->ip_src = nat->nat_inip;
137 ipn = nat_new(nat->nat_ptr, ip, &fi, IPN_TCP|FI_W_DPORT,
140 ipn->nat_age = fr_defnatage;
142 (void) fr_addstate(ip, &fi, FI_W_DPORT);
150 int ippr_rcmd_out(fin, ip, aps, nat)
156 return ippr_rcmd_portmsg(fin, ip, aps, nat);