diff options
Diffstat (limited to 'net/tipc/msg.c')
-rw-r--r-- | net/tipc/msg.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/net/tipc/msg.c b/net/tipc/msg.c index 73dcd00d674e..381063817b41 100644 --- a/net/tipc/msg.c +++ b/net/tipc/msg.c | |||
@@ -40,6 +40,100 @@ | |||
40 | #include "msg.h" | 40 | #include "msg.h" |
41 | #include "bearer.h" | 41 | #include "bearer.h" |
42 | 42 | ||
43 | u32 tipc_msg_tot_importance(struct tipc_msg *m) | ||
44 | { | ||
45 | if (likely(msg_isdata(m))) { | ||
46 | if (likely(msg_orignode(m) == tipc_own_addr)) | ||
47 | return msg_importance(m); | ||
48 | return msg_importance(m) + 4; | ||
49 | } | ||
50 | if ((msg_user(m) == MSG_FRAGMENTER) && | ||
51 | (msg_type(m) == FIRST_FRAGMENT)) | ||
52 | return msg_importance(msg_get_wrapped(m)); | ||
53 | return msg_importance(m); | ||
54 | } | ||
55 | |||
56 | |||
57 | void tipc_msg_init(struct tipc_msg *m, u32 user, u32 type, | ||
58 | u32 hsize, u32 destnode) | ||
59 | { | ||
60 | memset(m, 0, hsize); | ||
61 | msg_set_version(m); | ||
62 | msg_set_user(m, user); | ||
63 | msg_set_hdr_sz(m, hsize); | ||
64 | msg_set_size(m, hsize); | ||
65 | msg_set_prevnode(m, tipc_own_addr); | ||
66 | msg_set_type(m, type); | ||
67 | if (!msg_short(m)) { | ||
68 | msg_set_orignode(m, tipc_own_addr); | ||
69 | msg_set_destnode(m, destnode); | ||
70 | } | ||
71 | } | ||
72 | |||
73 | /** | ||
74 | * tipc_msg_calc_data_size - determine total data size for message | ||
75 | */ | ||
76 | |||
77 | int tipc_msg_calc_data_size(struct iovec const *msg_sect, u32 num_sect) | ||
78 | { | ||
79 | int dsz = 0; | ||
80 | int i; | ||
81 | |||
82 | for (i = 0; i < num_sect; i++) | ||
83 | dsz += msg_sect[i].iov_len; | ||
84 | return dsz; | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * tipc_msg_build - create message using specified header and data | ||
89 | * | ||
90 | * Note: Caller must not hold any locks in case copy_from_user() is interrupted! | ||
91 | * | ||
92 | * Returns message data size or errno | ||
93 | */ | ||
94 | |||
95 | int tipc_msg_build(struct tipc_msg *hdr, | ||
96 | struct iovec const *msg_sect, u32 num_sect, | ||
97 | int max_size, int usrmem, struct sk_buff** buf) | ||
98 | { | ||
99 | int dsz, sz, hsz, pos, res, cnt; | ||
100 | |||
101 | dsz = tipc_msg_calc_data_size(msg_sect, num_sect); | ||
102 | if (unlikely(dsz > TIPC_MAX_USER_MSG_SIZE)) { | ||
103 | *buf = NULL; | ||
104 | return -EINVAL; | ||
105 | } | ||
106 | |||
107 | pos = hsz = msg_hdr_sz(hdr); | ||
108 | sz = hsz + dsz; | ||
109 | msg_set_size(hdr, sz); | ||
110 | if (unlikely(sz > max_size)) { | ||
111 | *buf = NULL; | ||
112 | return dsz; | ||
113 | } | ||
114 | |||
115 | *buf = buf_acquire(sz); | ||
116 | if (!(*buf)) | ||
117 | return -ENOMEM; | ||
118 | skb_copy_to_linear_data(*buf, hdr, hsz); | ||
119 | for (res = 1, cnt = 0; res && (cnt < num_sect); cnt++) { | ||
120 | if (likely(usrmem)) | ||
121 | res = !copy_from_user((*buf)->data + pos, | ||
122 | msg_sect[cnt].iov_base, | ||
123 | msg_sect[cnt].iov_len); | ||
124 | else | ||
125 | skb_copy_to_linear_data_offset(*buf, pos, | ||
126 | msg_sect[cnt].iov_base, | ||
127 | msg_sect[cnt].iov_len); | ||
128 | pos += msg_sect[cnt].iov_len; | ||
129 | } | ||
130 | if (likely(res)) | ||
131 | return dsz; | ||
132 | |||
133 | buf_discard(*buf); | ||
134 | *buf = NULL; | ||
135 | return -EFAULT; | ||
136 | } | ||
43 | 137 | ||
44 | #ifdef CONFIG_TIPC_DEBUG | 138 | #ifdef CONFIG_TIPC_DEBUG |
45 | 139 | ||