-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
867 additions
and
3 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2021 Antrea Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package multicast | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
"syscall" | ||
) | ||
|
||
// The following constants and structs come from the linux kernel file | ||
// linux/include/uapi/linux/mroute.h | ||
const ( | ||
IGMPMSG_NOCACHE = 1 | ||
VIFF_USE_IFINDEX = 8 | ||
MRT_ADD_VIF = 202 | ||
MRT_DEL_VIF = 203 | ||
MRT_ADD_MFC = 204 | ||
MRT_DEL_MFC = 205 | ||
MRT_BASE = 200 | ||
MRT_TABLE = 209 | ||
MRT_FLUSH = 212 | ||
MAXVIFS = 32 | ||
) | ||
|
||
type vifctl struct { | ||
vifcVifi uint16 | ||
vifcFlags uint8 | ||
vifcThreshold uint8 | ||
vifcRateLimit uint32 | ||
vifcLclIfindex int | ||
vifcRmtAddr [4]byte | ||
} | ||
|
||
type mfcctl struct { | ||
mfccOrigin [4]byte | ||
mfccMcastgrp [4]byte | ||
mfccParent uint16 | ||
mfccTtls [32]byte | ||
mfccPktCnt uint32 | ||
mfccByteCnt uint32 | ||
mfccWrongIf uint32 | ||
mfccExpire int | ||
} | ||
|
||
// We should consider the changes in vifctl struct after kernel versiopn 5.9 | ||
func parseKernelVersion() (*kernelVersion, error) { | ||
var uname syscall.Utsname | ||
if err := syscall.Uname(&uname); err != nil { | ||
return nil, fmt.Errorf("Running uname error: %v", err) | ||
} | ||
kernel_version_full := arrayToString(uname.Release) | ||
kernel_version_numbers := strings.Split(kernel_version_full, "-") | ||
kernel_version_array := strings.Split(kernel_version_numbers[0], ".") | ||
major, err := strconv.Atoi(kernel_version_array[0]) | ||
minor, err := strconv.Atoi(kernel_version_array[1]) | ||
patch, err := strconv.Atoi(kernel_version_array[2]) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse kernel version %s", kernel_version_full) | ||
} | ||
return &kernelVersion{ | ||
major: major, | ||
minor: minor, | ||
patch: patch, | ||
}, nil | ||
} | ||
|
||
func arrayToString(x [65]int8) string { | ||
var buf [65]byte | ||
for i, b := range x { | ||
buf[i] = byte(b) | ||
} | ||
str := string(buf[:]) | ||
if i := strings.Index(str, "\x00"); i != -1 { | ||
str = str[:i] | ||
} | ||
return str | ||
} | ||
|
||
type kernelVersion struct { | ||
major int | ||
minor int | ||
patch int | ||
} |
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.