2 * $Id: ip_rcmd_pxy.c,v 1.4.2.6 2002/10/01 15:24:59 darrenr Exp $
5 * Simple RCMD transparent proxy for in-kernel use. For use with the NAT
8 #if SOLARIS && defined(_KERNEL)
9 extern kmutex_t ipf_rw;
12 #define isdigit(x) ((x) >= '0' && (x) <= '9')
14 #define IPF_RCMD_PROXY
17 int ippr_rcmd_init __P((void));
18 int ippr_rcmd_new __P((fr_info_t *, ip_t *, ap_session_t *, nat_t *));
19 int ippr_rcmd_out __P((fr_info_t *, ip_t *, ap_session_t *, nat_t *));
20 u_short ipf_rcmd_atoi __P((char *));
21 int ippr_rcmd_portmsg __P((fr_info_t *, ip_t *, ap_session_t *, nat_t *));
23 static frentry_t rcmdfr;
27 * RCMD application proxy initialization.
31 bzero((char *)&rcmdfr, sizeof(rcmdfr));
33 rcmdfr.fr_flags = FR_INQUE|FR_PASS|FR_QUICK|FR_KEEPSTATE;
39 * Setup for a new RCMD proxy.
41 int ippr_rcmd_new(fin, ip, aps, nat)
47 tcphdr_t *tcp = (tcphdr_t *)fin->fin_dp;
49 aps->aps_psiz = sizeof(u_32_t);
50 KMALLOCS(aps->aps_data, u_32_t *, sizeof(u_32_t));
51 if (aps->aps_data == NULL)
53 *(u_32_t *)aps->aps_data = 0;
54 aps->aps_sport = tcp->th_sport;
55 aps->aps_dport = tcp->th_dport;
61 * ipf_rcmd_atoi - implement a simple version of atoi
63 u_short ipf_rcmd_atoi(ptr)
66 register char *s = ptr, c;
67 register u_short i = 0;
69 while ((c = *s++) && isdigit(c)) {
77 int ippr_rcmd_portmsg(fin, ip, aps, nat)
86 tcphdr_t *tcp, tcph, *tcp2 = &tcph;
95 tcp = (tcphdr_t *)fin->fin_dp;
97 if (tcp->th_flags & TH_SYN) {
98 *(u_32_t *)aps->aps_data = htonl(ntohl(tcp->th_seq) + 1);
102 if ((*(u_32_t *)aps->aps_data != 0) &&
103 (tcp->th_seq != *(u_32_t *)aps->aps_data))
106 off = fin->fin_hlen + (tcp->th_off << 2);
111 dlen = msgdsize(m) - off;
112 bzero(portbuf, sizeof(portbuf));
113 copyout_mblk(m, off, MIN(sizeof(portbuf), dlen), portbuf);
115 m = *(mb_t **)fin->fin_mp;
116 dlen = mbufchainlen(m) - off;
117 bzero(portbuf, sizeof(portbuf));
118 m_copydata(m, off, MIN(sizeof(portbuf), dlen), portbuf);
121 portbuf[sizeof(portbuf) - 1] = '\0';
123 sp = ipf_rcmd_atoi(s);
128 * Add skeleton NAT entry for connection which will come back the
131 bcopy((char *)fin, (char *)&fi, sizeof(fi));
133 fi.fin_data[1] = fin->fin_data[1];
134 ipn = nat_outlookup(&fi, IPN_TCP, nat->nat_p, nat->nat_inip,
140 ip->ip_len = fin->fin_hlen + sizeof(*tcp);
141 bzero((char *)tcp2, sizeof(*tcp2));
142 tcp2->th_win = htons(8192);
143 tcp2->th_sport = htons(sp);
144 tcp2->th_dport = 0; /* XXX - don't specify remote port */
146 tcp2->th_flags = TH_SYN;
148 fi.fin_dp = (char *)tcp2;
149 fi.fin_dlen = sizeof(*tcp2);
151 ip->ip_src = nat->nat_inip;
152 ipn = nat_new(&fi, ip, nat->nat_ptr, NULL, IPN_TCP|FI_W_DPORT,
155 ipn->nat_age = fr_defnatage;
157 (void) fr_addstate(ip, &fi, NULL,
158 FI_W_DPORT|FI_IGNOREPKT);
167 int ippr_rcmd_out(fin, ip, aps, nat)
173 return ippr_rcmd_portmsg(fin, ip, aps, nat);