-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setns: replace env with netlink for bootstrap data
replace passing of pid and console path via environment variable with passing them with netlink message via an established pipe. this change requires us to set _LIBCONTAINER_INITTYPE and _LIBCONTAINER_INITPIPE as the env environment of the bootstrap process as we only send the bootstrap data for setns process right now. When init and setns bootstrap process are unified (i.e., init use nsexec instead of Go to clone new process), we can remove _LIBCONTAINER_INITTYPE. Note: - we read nlmsghdr first before reading the content so we can get the total length of the payload and allocate buffer properly instead of allocating one large buffer. - check read bytes vs the wanted number. It's an error if we failed to read the desired number of bytes from the pipe into the buffer. Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com>
- Loading branch information
Showing
4 changed files
with
243 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// +build linux | ||
package libcontainer | ||
|
||
import ( | ||
"syscall" | ||
|
||
"github.com/vishvananda/netlink/nl" | ||
) | ||
|
||
// list of known message types we want to send to bootstrap program | ||
// The number is randomly chosen to not conflict with known netlink types | ||
const ( | ||
InitMsg uint16 = 62000 | ||
PidAttr uint16 = 27281 | ||
ConsolePathAttr uint16 = 27282 | ||
) | ||
|
||
type Int32msg struct { | ||
Type uint16 | ||
Value uint32 | ||
} | ||
|
||
// int32msg has the following representation | ||
// | nlattr len | nlattr type | | ||
// | uint32 value | | ||
func (msg *Int32msg) Serialize() []byte { | ||
buf := make([]byte, msg.Len()) | ||
native := nl.NativeEndian() | ||
native.PutUint16(buf[0:2], uint16(msg.Len())) | ||
native.PutUint16(buf[2:4], msg.Type) | ||
native.PutUint32(buf[4:8], msg.Value) | ||
return buf | ||
} | ||
|
||
func (msg *Int32msg) Len() int { | ||
return syscall.NLA_HDRLEN + 4 | ||
} | ||
|
||
// bytemsg has the following representation | ||
// | nlattr len | nlattr type | | ||
// | value | pad | | ||
type Bytemsg struct { | ||
Type uint16 | ||
Value []byte | ||
} | ||
|
||
func (msg *Bytemsg) Serialize() []byte { | ||
l := msg.Len() | ||
buf := make([]byte, (l+syscall.NLA_ALIGNTO-1) & ^(syscall.NLA_ALIGNTO-1)) | ||
native := nl.NativeEndian() | ||
native.PutUint16(buf[0:2], uint16(l)) | ||
native.PutUint16(buf[2:4], msg.Type) | ||
copy(buf[4:], msg.Value) | ||
return buf | ||
} | ||
|
||
func (msg *Bytemsg) Len() int { | ||
return syscall.NLA_HDRLEN + len(msg.Value) + 1 // null-terminated | ||
} |
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.