コード例 #1
0
static int 
protohandlerin(struct libalias *la, struct ip *pip, struct alias_data *ah)
{
	
	AliasHandlePptpIn(la, pip, ah->lnk);
	return (0);
}
コード例 #2
0
ファイル: alias.c プロジェクト: juanfra684/DragonFlyBSD
static int
TcpAliasIn(struct ip *pip)
{
    struct tcphdr *tc;
    struct alias_link *link;

    tc = (struct tcphdr *) ((char *) pip + (pip->ip_hl << 2));

    link = FindUdpTcpIn(pip->ip_src, pip->ip_dst,
                        tc->th_sport, tc->th_dport,
                        IPPROTO_TCP,
                        !(packetAliasMode & PKT_ALIAS_PROXY_ONLY));
    if (link != NULL)
    {
        struct in_addr alias_address;
        struct in_addr original_address;
        struct in_addr proxy_address;
        u_short alias_port;
        u_short proxy_port;
        int accumulate;
        u_short *sptr;

/* Special processing for IP encoding protocols */
        if (ntohs(tc->th_dport) == PPTP_CONTROL_PORT_NUMBER
         || ntohs(tc->th_sport) == PPTP_CONTROL_PORT_NUMBER)
            AliasHandlePptpIn(pip, link);

        alias_address = GetAliasAddress(link);
        original_address = GetOriginalAddress(link);
        proxy_address = GetProxyAddress(link);
        alias_port = tc->th_dport;
        tc->th_dport = GetOriginalPort(link);
        proxy_port = GetProxyPort(link);

/* Adjust TCP checksum since destination port is being unaliased */
/* and destination port is being altered.                        */
        accumulate  = alias_port;
        accumulate -= tc->th_dport;
        sptr = (u_short *) &alias_address;
        accumulate += *sptr++;
        accumulate += *sptr;
        sptr = (u_short *) &original_address;
        accumulate -= *sptr++;
        accumulate -= *sptr;

/* If this is a proxy, then modify the TCP source port and
   checksum accumulation */
        if (proxy_port != 0)
        {
            accumulate += tc->th_sport;
            tc->th_sport = proxy_port;
            accumulate -= tc->th_sport;

            sptr = (u_short *) &pip->ip_src;
            accumulate += *sptr++;
            accumulate += *sptr;
            sptr = (u_short *) &proxy_address;
            accumulate -= *sptr++;
            accumulate -= *sptr;
        }

/* See if ACK number needs to be modified */
        if (GetAckModified(link) == 1)
        {
            int delta;

            delta = GetDeltaAckIn(pip, link);
            if (delta != 0)
            {
                sptr = (u_short *) &tc->th_ack;
                accumulate += *sptr++;
                accumulate += *sptr;
                tc->th_ack = htonl(ntohl(tc->th_ack) - delta);
                sptr = (u_short *) &tc->th_ack;
                accumulate -= *sptr++;
                accumulate -= *sptr;
            }
        }

        ADJUST_CHECKSUM(accumulate, tc->th_sum);

/* Restore original IP address */
        sptr = (u_short *) &pip->ip_dst;
        accumulate  = *sptr++;
        accumulate += *sptr;
        pip->ip_dst = original_address;
        sptr = (u_short *) &pip->ip_dst;
        accumulate -= *sptr++;
        accumulate -= *sptr;

/* If this is a transparent proxy packet, then modify the source
   address */
        if (proxy_address.s_addr != 0)
        {
            sptr = (u_short *) &pip->ip_src;
            accumulate += *sptr++;
            accumulate += *sptr;
            pip->ip_src = proxy_address;
            sptr = (u_short *) &pip->ip_src;
            accumulate -= *sptr++;
            accumulate -= *sptr;
        }

        ADJUST_CHECKSUM(accumulate, pip->ip_sum);

/* Monitor TCP connection state */
        TcpMonitorIn(pip, link);

        return(PKT_ALIAS_OK);
    }
    return(PKT_ALIAS_IGNORED);
}