kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* Question about memory in C
@ 2016-02-10 13:40 Victor Detoni
  2016-02-10 13:54 ` Skm Prabhu
  2016-02-10 21:25 ` Cihangir Akturk
  0 siblings, 2 replies; 5+ messages in thread
From: Victor Detoni @ 2016-02-10 13:40 UTC (permalink / raw)
  To: kernelnewbies

Hi all,

I'm working for a network security prototype and I would like to know the
best way to read diferent configs from the memory, for example:

My program will receive many pkts from network interface and it needs to
know what's profile it will use based on source ip address.

First all, I'm thinking to use array in C, for example:

for (i=0;i<=PROFILES;i++) {
    if (pkt.ip_addr == source_ip[i])
        do_something(pkt,i)
}

I will process@about millions entries per second and ~100 profiles. What
do you think? It will work fine? fast? any suggest?

thanks
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160210/6b978809/attachment.html 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Question about memory in C
  2016-02-10 13:40 Question about memory in C Victor Detoni
@ 2016-02-10 13:54 ` Skm Prabhu
  2016-02-10 21:25 ` Cihangir Akturk
  1 sibling, 0 replies; 5+ messages in thread
From: Skm Prabhu @ 2016-02-10 13:54 UTC (permalink / raw)
  To: kernelnewbies

I think reading file sequentially & process it is a good idea for huge
chunk of data. Just think about sort the data in someway (i feel, index
sort or hashing would be great) & use some search mechanism. Again it is
all depends on sort & search algorithm.

On Wed, Feb 10, 2016 at 7:10 PM, Victor Detoni <victordetoni@gmail.com>
wrote:

> Hi all,
>
> I'm working for a network security prototype and I would like to know the
> best way to read diferent configs from the memory, for example:
>
> My program will receive many pkts from network interface and it needs to
> know what's profile it will use based on source ip address.
>
> First all, I'm thinking to use array in C, for example:
>
> for (i=0;i<=PROFILES;i++) {
>     if (pkt.ip_addr == source_ip[i])
>         do_something(pkt,i)
> }
>
> I will process at about millions entries per second and ~100 profiles.
> What do you think? It will work fine? fast? any suggest?
>
> thanks
> Victor
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160210/6feb6984/attachment.html 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Question about memory in C
  2016-02-10 13:40 Question about memory in C Victor Detoni
  2016-02-10 13:54 ` Skm Prabhu
@ 2016-02-10 21:25 ` Cihangir Akturk
  2016-02-10 22:49   ` Victor Detoni
  1 sibling, 1 reply; 5+ messages in thread
From: Cihangir Akturk @ 2016-02-10 21:25 UTC (permalink / raw)
  To: kernelnewbies

On Wed, Feb 10, 2016 at 11:40:44AM -0200, Victor Detoni wrote:
> Hi all,
> 
> I'm working for a network security prototype and I would like to know the
> best way to read diferent configs from the memory, for example:
> 
> My program will receive many pkts from network interface and it needs to
> know what's profile it will use based on source ip address.
> 
> First all, I'm thinking to use array in C, for example:
> 
> for (i=0;i<=PROFILES;i++) {
>     if (pkt.ip_addr == source_ip[i])
>         do_something(pkt,i)
> }
> 
> I will process at about millions entries per second and ~100 profiles. What
> do you think? It will work fine? fast? any suggest?
> 
> thanks
> Victor

Hi Victor,

I would consider using a simple hash table. Use ipaddr as a key to
do fast lookup of the value. Take a look at scripts/fixdep.c which
includes a FNV hash table implementation.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Question about memory in C
  2016-02-10 21:25 ` Cihangir Akturk
@ 2016-02-10 22:49   ` Victor Detoni
  2016-02-10 23:19     ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: Victor Detoni @ 2016-02-10 22:49 UTC (permalink / raw)
  To: kernelnewbies

Hi,

Thank you for your tip! I really appreciate it. In my situation I will have
many profiles and for each profile I can have many ip address, for example:

profile 1:
192.168.0.0/24
192.168.1.2/32
192.168.14/23
...

profile 2:
10.10.10.0/24
10.11.12.0/23
...

What's your opinion? I'm thinking to use pcap library, but I still haven't
the key.

On Wed, Feb 10, 2016 at 7:25 PM, Cihangir Akturk <cakturk@gmail.com> wrote:

> On Wed, Feb 10, 2016 at 11:40:44AM -0200, Victor Detoni wrote:
> > Hi all,
> >
> > I'm working for a network security prototype and I would like to know the
> > best way to read diferent configs from the memory, for example:
> >
> > My program will receive many pkts from network interface and it needs to
> > know what's profile it will use based on source ip address.
> >
> > First all, I'm thinking to use array in C, for example:
> >
> > for (i=0;i<=PROFILES;i++) {
> >     if (pkt.ip_addr == source_ip[i])
> >         do_something(pkt,i)
> > }
> >
> > I will process at about millions entries per second and ~100 profiles.
> What
> > do you think? It will work fine? fast? any suggest?
> >
> > thanks
> > Victor
>
> Hi Victor,
>
> I would consider using a simple hash table. Use ipaddr as a key to
> do fast lookup of the value. Take a look at scripts/fixdep.c which
> includes a FNV hash table implementation.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160210/38501f25/attachment.html 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Question about memory in C
  2016-02-10 22:49   ` Victor Detoni
@ 2016-02-10 23:19     ` Greg KH
  0 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2016-02-10 23:19 UTC (permalink / raw)
  To: kernelnewbies

On Wed, Feb 10, 2016 at 08:49:30PM -0200, Victor Detoni wrote:
> Hi,
> 
> Thank you for your tip! I really appreciate it. In my situation I will have
> many profiles and for each profile I can have many ip address, for example:
> 
> profile 1:
> 192.168.0.0/24
> 192.168.1.2/32
> 192.168.14/23
> ...
> 
> profile 2:
> 10.10.10.0/24
> 10.11.12.0/23
> ...
> 
> What's your opinion? I'm thinking to use pcap library, but I still haven't the
> key.

I think you have a long way to go before you need to worry about stuff
like this.  Why not test and see exactly _where_ the performance
problems are before trying to solve things you don't know are actually
problems yet.

good luck,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-02-10 23:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-10 13:40 Question about memory in C Victor Detoni
2016-02-10 13:54 ` Skm Prabhu
2016-02-10 21:25 ` Cihangir Akturk
2016-02-10 22:49   ` Victor Detoni
2016-02-10 23:19     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).