-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround non-standardized TUN message types.
Also minor refactoring.
- Loading branch information
Caleb James DeLisle
committed
Dec 10, 2012
1 parent
f96202e
commit b0472e8
Showing
23 changed files
with
200 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,31 @@ | |||
/* vim: set expandtab ts=4 sw=4: */ | |||
/* | |||
* You may redistribute this program and/or modify it under the terms of | |||
* the GNU General Public License as published by the Free Software Foundation, | |||
* either version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#include "interface/TUNMessageType.h" | |||
#include "wire/Message.h" | |||
|
|||
#include <stdint.h> | |||
|
|||
void TUNMessageType_push(struct Message* message, uint16_t ethertype) | |||
{ | |||
Message_shift(message, 4); | |||
((uint16_t*) message->bytes)[0] = 0; | |||
((uint16_t*) message->bytes)[1] = ethertype; | |||
} | |||
|
|||
uint16_t TUNMessageType_pop(struct Message* message) | |||
{ | |||
Message_shift(message, -4); | |||
return ((uint16_t*) message->bytes)[-1]; | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,26 @@ | |||
/* vim: set expandtab ts=4 sw=4: */ | |||
/* | |||
* You may redistribute this program and/or modify it under the terms of | |||
* the GNU General Public License as published by the Free Software Foundation, | |||
* either version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef TUNMessageType_H | |||
#define TUNMessageType_H | |||
|
|||
#include "wire/Message.h" | |||
|
|||
#include <stdint.h> | |||
|
|||
void TUNMessageType_push(struct Message* message, uint16_t ethertype); | |||
|
|||
uint16_t TUNMessageType_pop(struct Message* message); | |||
|
|||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,39 @@ | |||
/* vim: set expandtab ts=4 sw=4: */ | |||
/* | |||
* You may redistribute this program and/or modify it under the terms of | |||
* the GNU General Public License as published by the Free Software Foundation, | |||
* either version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#include "wire/Message.h" | |||
#include "interface/TUNMessageType.h" | |||
#include "wire/Ethernet.h" | |||
|
|||
#include <stdint.h> | |||
|
|||
/** | |||
* Illumos has no consept of packet info, it only supports IPv4 and IPv6 | |||
* through TUN devices and it detects it by reading the version byte. | |||
*/ | |||
|
|||
static inline ethertypeForPacketType(uint8_t highByte) | |||
{ | |||
return ((message->bytes[0] >> 4) == 6) ? Ethernet_TYPE_IP6 : Ethernet_TYPE_IP4; | |||
} | |||
|
|||
void TUNMessageType_push(struct Message* message, uint16_t ethertype) | |||
{ | |||
Assert_true(ethertype == ethertypeForPacketType(message->bytes[0])); | |||
} | |||
|
|||
uint16_t TUNMessageType_pop(struct Message* message) | |||
{ | |||
return ethertypeForPacketType(message->bytes[0]); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,42 @@ | |||
/* vim: set expandtab ts=4 sw=4: */ | |||
/* | |||
* You may redistribute this program and/or modify it under the terms of | |||
* the GNU General Public License as published by the Free Software Foundation, | |||
* either version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#include "wire/Message.h" | |||
#include "interface/TUNMessageType.h" | |||
#include "wire/Ethernet.h" | |||
|
|||
#include <stdint.h> | |||
#include <netinet/in.h> | |||
|
|||
/** | |||
* OSX is broken and expects you to send the platform dependent | |||
* address family type rather than the ethertype. | |||
*/ | |||
|
|||
void TUNMessageType_push(struct Message* message, uint16_t ethertype) | |||
{ | |||
uint16_t afType = (ethertype == Ethernet_TYPE_IP6) ? AF_INET6 : AF_INET; | |||
|
|||
Message_shift(message, 4); | |||
((uint16_t*) message->bytes)[0] = 0; | |||
((uint16_t*) message->bytes)[1] = afType; | |||
} | |||
|
|||
uint16_t TUNMessageType_pop(struct Message* message) | |||
{ | |||
Message_shift(message, -4); | |||
uint16_t afType = ((uint16_t*) message->bytes)[-1]; | |||
|
|||
return (afType == AF_INET6) ? Ethernet_TYPE_IP6 : Ethernet_TYPE_IP4; | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.