From: Alexander Nasonov <alnsn-mycop@yandex.ru>
To: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Cc: netfilter-devel@lists.netfilter.org
Subject: Re: ASN.1 decoder for h323-conntrack-nat
Date: Fri, 17 Oct 2003 11:37:49 +0200 [thread overview]
Message-ID: <3F8FB86D.8070401@yandex.ru> (raw)
In-Reply-To: <Pine.LNX.4.33.0310170956080.7119-100000@blackhole.kfki.hu>
Jozsef Kadlecsik wrote:
>Such optimizations would be highly preferred. The code ran not only
>faster but I think were smaller as well.
>
>
I've just finished an analysis of CloseLogicalChannel. It's amazing how
greatly it can be reduced after optimization.
LogicalChannelNumber ::=INTEGER (1..65535)
CloseLogicalChannel ::=SEQUENCE
{
forwardLogicalChannelNumber LogicalChannelNumber,
source CHOICE
{
user NULL,
lcse NULL
},
...,
reason CHOICE
{
unknown NULL,
reopen NULL,
reservationFailure NULL,
...
}
}
1. CloseLogicalChannel is a sequence without optional/default fields and
with extention => first bit signal the presense of extention(s)
2. LogicalChannelNumber is aligned two bytes => data after this field is
aligned
3. "source" choice has two choices and no extention => one bit: 0 for
user, 1 for lcse. This is bit 7 (most significant) because of previous item.
4. user and lcse are NULL => no bits
int CloseLogicalChannel(asn1_message_data* asn)
{
// 3 = one byte for alignement + two bytes for LogicalChannelNumber
+ one byte for "source" field
if(asn->bytes_left <= 3)
return ERROR_UNEXPECTED_END;
bool hasExtentions = asn->current_byte & (1 << asn->bit_position);
asn->bytes_left -= 3;
asn->current_byte += 3;
asn->bit_position = 6; // bit 7 is used by "source" field
return hasExtentions ? skip_sequence_extentions(asn) : SUCCESS;
}
Compare it with a current code to see the difference (unexpected end of
data is signaled by throwing C++ exception from functions):
void f_MSC__CloseLogicalChannel_source__user()
{
// NULL
}
void f_MSC__CloseLogicalChannel_source__lcse()
{
// NULL
}
void f_MSC__CloseLogicalChannel_source()
{
// CHOICE { < 2 field(s) > }
size_t len;
unsigned char* saved_byte;
unsigned int choice = GetBits1();
switch(choice)
{
case 0:
f_MSC__CloseLogicalChannel_source__user();
break;
case 1:
f_MSC__CloseLogicalChannel_source__lcse();
break;
}
}
void f_MSC__LogicalChannelNumber()
{
// INTEGER(1..65535)
Align();
unsigned int byte1 = GetByte();
unsigned int byte2 = GetByte();
unsigned long value = 1 + (256 * byte1 + byte2);
}
void f_MSC__CloseLogicalChannel__forwardLogicalChannelNumber()
{
f_MSC__LogicalChannelNumber();
}
void f_MSC__CloseLogicalChannel__source()
{
f_MSC__CloseLogicalChannel_source();
}
void f_MSC__CloseLogicalChannel()
{
// SEQUENCE { < 2 field(s) > ,..., < 1 field(s) > }
unsigned int bits = GetBits1();
f_MSC__CloseLogicalChannel__forwardLogicalChannelNumber();
f_MSC__CloseLogicalChannel__source();
if(bits) // extentions?
{
bool ext[1];
size_t extCount = GetNormallySmallLength();
ReadBitmap(ext, extCount > 1 ? 1 : extCount);
size_t extSkip = extCount > 1 ? CountSetBits(extCount - 1) : 0;
if(extCount > 0 && ext[0])
{
size_t len = GetSemiConstrainedLength();
unsigned char* saved_byte = m_byte;
f_MSC__CloseLogicalChannel__reason();
m_byte = saved_byte;
SkipBytes(len);
}
for(; extSkip; --extSkip)
SkipDataWithSemiConstrainedLength();
}
}
--
Alexaner Nasonov
prev parent reply other threads:[~2003-10-17 9:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-16 13:25 ASN.1 decoder for h323-conntrack-nat Alexander Nasonov
2003-10-16 13:42 ` Jozsef Kadlecsik
2003-10-16 14:11 ` Alexander Nasonov
2003-10-17 8:02 ` Jozsef Kadlecsik
2003-10-17 9:37 ` Alexander Nasonov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3F8FB86D.8070401@yandex.ru \
--to=alnsn-mycop@yandex.ru \
--cc=kadlec@blackhole.kfki.hu \
--cc=netfilter-devel@lists.netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.