LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-14-2014, 12:49 AM   #1
poplinux
Member
 
Registered: May 2012
Posts: 111

Rep: Reputation: Disabled
How to create VLAN interface(in linux kernel)?


Dear Sir.

My old linux kernel(Ver 2.6.21.7) are create VLAN intface using register_vlan_device() API.
Code:
struct net_device *trunk = NULL;
struct net_device *vlan  = NULL;

trunk = dev_get_by_name(&init_net, "eth0");
vlan  = register_vlan_device(trunk, 10);

But my new linux kernel(Ver 2.6.32.27) are not support this way, and change another way. I guess.


Please show to me or advise to me. "How to create vlan in linux kernel"


Thank you.
 
Old 07-15-2014, 02:02 AM   #2
GaWdLy
Member
 
Registered: Feb 2013
Location: San Jose, CA
Distribution: RHEL/CentOS/Fedora
Posts: 457

Rep: Reputation: Disabled
These instructions should work for 2.6.32-x kernels.

http://www.reddit.com/r/linuxadmin/c..._tagging_need/
 
Old 07-15-2014, 08:40 PM   #3
poplinux
Member
 
Registered: May 2012
Posts: 111

Original Poster
Rep: Reputation: Disabled
Dear GaWdLy.

Thank's your reply.

But, your reply is not helply to me.

I'm already know "how to create vlan interface on user space". see below.

Code:
sudo ip link add link eth0 name eth0.5 type vlan id 5
But, My question is "How to create vlan interface in KERNEL SPACE, using kernel api".

However, Thank's your advisce.

Thank you.
 
Old 07-15-2014, 09:50 PM   #4
GaWdLy
Member
 
Registered: Feb 2013
Location: San Jose, CA
Distribution: RHEL/CentOS/Fedora
Posts: 457

Rep: Reputation: Disabled
I see a reference that implies that the kernel API for vlans might have been removed?

http://lists.shmoo.com/pipermail/hos...ly/026292.html

So I guess there's a possibility that you need to use netlink, as opposed to the "old" kernel API...
 
Old 07-16-2014, 04:24 AM   #5
poplinux
Member
 
Registered: May 2012
Posts: 111

Original Poster
Rep: Reputation: Disabled
Dear GaWdLy.

Thank's your reply.

But It is user space too.

I'm found some way from Documentation/generic_netlink.txt.

This document say to me that see http://www.linuxfoundation.org/colla..._netlink_howto

And I'm found very useful document on this site.

Thank you.
 
Old 07-16-2014, 03:49 PM   #6
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,737

Rep: Reputation: 154Reputation: 154
You can try to call 'vlan_ioctl_set' to create VLAN.
 
Old 07-16-2014, 08:53 PM   #7
poplinux
Member
 
Registered: May 2012
Posts: 111

Original Poster
Rep: Reputation: Disabled
Dear nini09.

Thank's your advise.

I'm searching "vlan_ioctl_set()" from linux kernel tree(2.6.32). And found this API in "net/socket.c".

This api purpose are register "ioctl" api to subsystem, I guess.

"net/8021q/vlan.c::vlan_proto_init()" is registed vlan_ioctl_handler() api to subsystem using "vlan_ioctl_set" api.

Can you show to me pseudocode? - "How to create vlan interface using vlan_ioctl_set()" -

Thank you.
 
Old 07-17-2014, 03:44 PM   #8
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,737

Rep: Reputation: 154Reputation: 154
I checked code again. The ioctl has to be called from user space only.
Why do you need to create a VLAN in kernel space?
 
Old 07-17-2014, 08:44 PM   #9
poplinux
Member
 
Registered: May 2012
Posts: 111

Original Poster
Rep: Reputation: Disabled
Dear nini09.

Thank's your reply.

Because my customer required "Must create in kernel space".

Older kernel is possible without error(2.6.21). But kernel version (2.6.32.27) not support this way.

I guess, 2.6.32.27 are support another way. ex) direct call some API or Using netlink API.

But I'm can't found some example code, using netlink api.


Thank you.
 
Old 07-22-2014, 04:19 PM   #10
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,737

Rep: Reputation: 154Reputation: 154
Following link might help a little but not complete. Just netlink example code in kernel, not relative to create VLAN.
http://stackoverflow.com/questions/1...x-linux-kernel
 
Old 11-15-2021, 12:19 PM   #11
hmatrix
LQ Newbie
 
Registered: Nov 2021
Location: Montreal,QC
Distribution: Ubuntu
Posts: 1

Rep: Reputation: Disabled
I know we are 2021 and the initial question was asked in 2014.
May I suggest an alternate solution which involves using the usermode-helper API, this basically allows kernel code to invoke user space programs/tool, thus from kernel one can run "ip ..." to create such vlan interface.
I know it is a little bit of a hack, but this is how some drivers used this API to upload firmware file that exist in user space file system into the chip (example wifi).

Personally I had used this feature as doing it in the kernel is too much complicated.

But hey, it is your system you do what ever needed.

Take care.

Hmatrix
 
Old 11-17-2021, 04:36 PM   #12
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 2,053

Rep: Reputation: 788Reputation: 788Reputation: 788Reputation: 788Reputation: 788Reputation: 788Reputation: 788
The 'ip' command is now the mostly used tool to do what we previously did with ifconfig and the like. You are correct in suggesting that.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Untagged vlan sub-interface pcCoder Linux - Networking 2 04-09-2014 12:06 PM
[SOLVED] Creating a VLAN interface on top of another VLAN interface jbbroccard2 Linux - Networking 1 05-22-2013 02:25 AM
How to create vlan in linux using cisco 3750 switch tushs Linux - Networking 3 05-25-2011 04:04 AM
Route non-vlan packet to a vlan interface mic.sed Linux - Networking 2 04-23-2010 03:39 AM
Help in Vlan-Interface Paris Heng Linux - Networking 1 03-02-2009 06:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration