Example #1
0
static int
protohandler2out(struct libalias *la, struct ip *pip, struct alias_data *ah)
{
	
	return (AliasHandleUdpNbtNS(la, pip, ah->lnk, &pip->ip_src, ah->sport,
 	    ah->aaddr, ah->aport));
}
Example #2
0
static int
protohandler2in(struct libalias *la, struct ip *pip, struct alias_data *ah)
{
	
	AliasHandleUdpNbtNS(la, pip, ah->lnk, ah->aaddr, ah->aport,
 			    ah->oaddr, ah->dport);
	return (0);
}
Example #3
0
static int
UdpAliasOut(struct ip *pip)
{
    struct udphdr *ud;
    struct alias_link *link;

/* Return if proxy-only mode is enabled */
    if (packetAliasMode & PKT_ALIAS_PROXY_ONLY)
        return PKT_ALIAS_OK;

    ud = (struct udphdr *) ((char *) pip + (pip->ip_hl << 2));

    link = FindUdpTcpOut(pip->ip_src, pip->ip_dst,
                         ud->uh_sport, ud->uh_dport,
                         IPPROTO_UDP, 1);
    if (link != NULL)
    {
        u_short alias_port;
        struct in_addr alias_address;

        alias_address = GetAliasAddress(link);
        alias_port = GetAliasPort(link);

/* Special processing for IP encoding protocols */
	if (ntohs(ud->uh_dport) == CUSEEME_PORT_NUMBER)
	    AliasHandleCUSeeMeOut(pip, link);
/* If NETBIOS Datagram, It should be alias address in UDP Data, too */
	else if (ntohs(ud->uh_dport) == NETBIOS_DGM_PORT_NUMBER
	      || ntohs(ud->uh_sport) == NETBIOS_DGM_PORT_NUMBER)
	    AliasHandleUdpNbt(pip, link, &alias_address, alias_port);
	else if (ntohs(ud->uh_dport) == NETBIOS_NS_PORT_NUMBER
	      || ntohs(ud->uh_sport) == NETBIOS_NS_PORT_NUMBER)
	    AliasHandleUdpNbtNS(pip, link, &pip->ip_src, &ud->uh_sport,
				&alias_address, &alias_port);
/*
 * We don't know in advance what TID the TFTP server will choose,
 * so we create a wilcard link (destination port is unspecified)
 * that will match any TID from a given destination.
 */
	else if (ntohs(ud->uh_dport) == TFTP_PORT_NUMBER)
	    FindRtspOut(pip->ip_src, pip->ip_dst,
			ud->uh_sport, alias_port, IPPROTO_UDP);

/* If UDP checksum is not zero, adjust since source port is */
/* being aliased and source address is being altered        */
        if (ud->uh_sum != 0)
        {
            int accumulate;
            u_short *sptr;

            accumulate  = ud->uh_sport;
            accumulate -= alias_port;
            sptr = (u_short *) &(pip->ip_src);
            accumulate += *sptr++;
            accumulate += *sptr;
            sptr = (u_short *) &alias_address;
            accumulate -= *sptr++;
            accumulate -= *sptr;
            ADJUST_CHECKSUM(accumulate, ud->uh_sum);
        }

/* Put alias port in UDP header */
        ud->uh_sport = alias_port;

/* Change source address */
        DifferentialChecksum(&pip->ip_sum,
                             (u_short *) &alias_address,
                             (u_short *) &pip->ip_src,
                             2);
        pip->ip_src = alias_address;

        return(PKT_ALIAS_OK);
    }
    return(PKT_ALIAS_IGNORED);
}
Example #4
0
static int
UdpAliasIn(struct ip *pip)
{
    struct udphdr *ud;
    struct alias_link *link;

/* Return if proxy-only mode is enabled */
    if (packetAliasMode & PKT_ALIAS_PROXY_ONLY)
        return PKT_ALIAS_OK;

    ud = (struct udphdr *) ((char *) pip + (pip->ip_hl << 2));

    link = FindUdpTcpIn(pip->ip_src, pip->ip_dst,
                        ud->uh_sport, ud->uh_dport,
                        IPPROTO_UDP, 1);
    if (link != NULL)
    {
        struct in_addr alias_address;
        struct in_addr original_address;
        u_short alias_port;
        int accumulate;
        u_short *sptr;
	int r = 0;

        alias_address = GetAliasAddress(link);
        original_address = GetOriginalAddress(link);
        alias_port = ud->uh_dport;
        ud->uh_dport = GetOriginalPort(link);

/* Special processing for IP encoding protocols */
	if (ntohs(ud->uh_dport) == CUSEEME_PORT_NUMBER)
	    AliasHandleCUSeeMeIn(pip, original_address);
/* If NETBIOS Datagram, It should be alias address in UDP Data, too */
	else if (ntohs(ud->uh_dport) == NETBIOS_DGM_PORT_NUMBER
	      || ntohs(ud->uh_sport) == NETBIOS_DGM_PORT_NUMBER)
	    r = AliasHandleUdpNbt(pip, link, &original_address, ud->uh_dport);
	else if (ntohs(ud->uh_dport) == NETBIOS_NS_PORT_NUMBER
	      || ntohs(ud->uh_sport) == NETBIOS_NS_PORT_NUMBER)
	    r = AliasHandleUdpNbtNS(pip, link, &alias_address, &alias_port,
				    &original_address, &ud->uh_dport);

/* If UDP checksum is not zero, then adjust since destination port */
/* is being unaliased and destination address is being altered.    */
        if (ud->uh_sum != 0)
        {
            accumulate  = alias_port;
            accumulate -= ud->uh_dport;
            sptr = (u_short *) &alias_address;
            accumulate += *sptr++;
            accumulate += *sptr;
            sptr = (u_short *) &original_address;
            accumulate -= *sptr++;
            accumulate -= *sptr;
            ADJUST_CHECKSUM(accumulate, ud->uh_sum);
        }

/* Restore original IP address */
        DifferentialChecksum(&pip->ip_sum,
                             (u_short *) &original_address,
                             (u_short *) &pip->ip_dst,
                             2);
        pip->ip_dst = original_address;

	/*
	 * If we cannot figure out the packet, ignore it.
	 */
	if (r < 0)
	    return(PKT_ALIAS_IGNORED);
	else
	    return(PKT_ALIAS_OK);
    }
    return(PKT_ALIAS_IGNORED);
}